Here's another way which reads the output directly in to you're program by using _popen(). This example is running the DIR command then printing the DIR output with printf(). Then you can write to file or anything, also modify the output.
void Dir(char* Path)
sprintf(CommandLine, "DIR %s", Path);
if ((fin = _popen(CommandLine, "r")) != NULL)
while( !feof( fin ) )
if( fgets( Buffer, 128, fin ) != NULL )
printf("My Output>>: " );
printf( Buffer );