int SysRunCommand( const char *cmd ) { int my_std_output; int my_std_error; ULONG bytes_read; int rc; HFILE readpipe; char buff[256 + 1]; APIRET rc2; readpipe = 0; my_std_output = dup( STDOUT_FILENO ); my_std_error = dup( STDERR_FILENO ); rc = SysRunCommandPipe( cmd, &readpipe ); dup2( my_std_output, STDOUT_FILENO ); dup2( my_std_error, STDERR_FILENO ); close( my_std_output ); close( my_std_error ); if( rc == -1 ) { if( readpipe != 0 ) DosClose( readpipe ); return( rc ); } if( readpipe != 0 ) { rc2 = DosRead( readpipe, buff, sizeof( buff ) - 1, &bytes_read ); while( rc2 == 0 && bytes_read != 0 ) { buff[bytes_read] = '\0'; Log( Quiet, "%s", buff ); rc2 = DosRead( readpipe, buff, sizeof( buff ) - 1, &bytes_read ); } DosClose( readpipe ); } /* free up the zombie (if there is one) */ while( wait( &rc ) == -1 && errno == EINTR ) ; return( rc ); }
int SysRunCommand( const char *cmd ) { int my_std_output; int my_std_error; int bytes_read; int rc; int readpipe = -1; char buff[256 + 1]; my_std_output = dup( STDOUT_FILENO ); my_std_error = dup( STDERR_FILENO ); rc = SysRunCommandPipe( cmd, &readpipe ); dup2( my_std_output, STDOUT_FILENO ); dup2( my_std_error, STDERR_FILENO ); close( my_std_output ); close( my_std_error ); if( rc == -1 ) { if( readpipe != -1 ) close( readpipe ); return( rc ); } if( readpipe != -1 ) { for( ;; ) { bytes_read = read( readpipe, buff, sizeof( buff ) - 1 ); if( bytes_read == 0 ) break; buff[bytes_read] = '\0'; Log( Quiet, "%s", buff ); } close( readpipe ); } /* free up the zombie (if there is one) */ while( wait( &rc ) == -1 && errno == EINTR ) ; return( rc ); }