心有法竹
dup2( STDIN_FILENO, newfd )全文如下:char reading[ 1025 ];int fdin = 0, r_control;if( dup2( STDIN_FILENO, fdin ) < 0 ){
perror( "dup2( )" );
exit( errno );}memset( reading, '\0', 1025 );while( ( r_control = read( fdin, reading, 1024 ) ) > 0 ){
printf( "<%s>", reading );
memset( reading, '\0', 1025 );}if( r_control < 0 )
perror( "read( )" ); close( fdin );但是,我认为fcntl可能是更好的解决方案echo "salut" | code