Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The popen() function opens a process by creating a pipe, forking and involking the
- shell.
- commandThatOutputs.exe > someFileToStoreResults.txt
- commandThatOutputs.exe | yourProgramToProcessInput.exe
- #include <stdlib.h>
- #include <stdio.h>
- int main(int argc, char* argv[])
- {
- FILE * fptr; // file holder
- char c; // char buffer
- system("dir >> temp.txt"); // call dir and put it's contents in a temp using redirects.
- fptr = fopen("temp.txt", "r"); // open said file for reading.
- // oh, and check for fptr being NULL.
- while(1){
- c = fgetc(fptr);
- if(c!= EOF)
- printf("%c", c); // do what you need to.
- else
- break; // exit when you hit the end of the file.
- }
- fclose(fptr); // don't call this is fptr is NULL.
- remove("temp.txt"); // clean up
- getchar(); // stop so I can see if it worked.
- }
Add Comment
Please, Sign In to add comment