#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define BUF_SIZE 128
int main( int argc, char *argv[] ) {
int fd_out;
int err;
(void)argc;
(void)argv;
fd_out = open( "/hello.txt", O_WRONLY );
if( fd_out < 0 ) {
printf( "open: error opening the file." );
return -1;
}
err = close( STDOUT_FILENO );
if( err ) {
printf( "close: could not close stdout." );
return -1;
}
dup2( fd_out, STDOUT_FILENO );
printf( "I should be seeing this message inside hello.txt\n" );
err = close( fd_out );
if( err )
return err;
return 0;
}