i want to save a system command's output in a file without displaying it on screen. i thought of defining stdout to the file i want and haven't tested it yet. Any other ideas?
i want to save a system command's output in a file without displaying it on screen. i thought of defining stdout to the file i want and haven't tested it yet. Any other ideas?
thanx
I have written this. It compiles fine, when i run it
the info file is created and hello world is written in the
file but then i get the "this program has performed an illegal
operation" error.
Error while opening file is not printed.
Code:#include <stdio.h> #include <stdlib.h> void copyFile (FILE * input, FILE * output) { int c; while ( (c=getc(input)) != EOF) putc(c,output); } int main () { FILE * pr; system("hello > c:\\info"); //hello just prints hello world if ((pr = fopen("r","c:\\info")) == NULL) fprintf(stderr, "Error while opening info file"); copyFile(pr, stdout); return 0; }
Also, checkout the (non-standard) popen() or _popen() function if you have it. It might be of some use to you, depending on what you're trying to accomplish.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]