Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

what is stdoutread in c++

// make a temp file to store the function's stdout
int newStdOut = mkstemp( "/tmp/stdout.XXXXXXX" );

// save the original stdout
int tmpStdOut = dup( STDOUT_FILENO );

// clear stdout
fflush( stdout );

// now point the stdout file descriptor to the file
dup2( newStdOut, STDOUT_FILENO );

// call the function we want to collect the stdout from
some_function();

// make sure stdout is empty
fflush( stdout );

// restore original stdout
dup2( tmpStdOut, STDOUT_FILENO );

// the tmp file now contains whatever some_function() wrote to stdout
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #stdoutread
ADD COMMENT
Topic
Name
4+4 =