-   Programming (
-   -   redirecting stdout to /dev/null and stderr to stdout? (

Thinking 05-18-2006 02:11 AM

redirecting stdout to /dev/null and stderr to stdout?

what i want:
execute another programm within my C app using popen(); and check if an error occured

how i try it:

FILE *fp = popen("someprog someparams 1>/dev/null 2>&1","r");
  int len = fread(buffer,sizeof(char),1024,fp);
      printf("WTF: AN ERROR!!!");
      error = true;

what i wanted to do:
redirect stdout to dev null and stderr to stdout, so i can read using popen and i only get stderr
just a simple schematic example:
"tar blablabla 1>/dev/null 2>&1" --> i get nothing
"tar blablabla" --> i get the error to stdout i wanted to read from stdin

another possibility would be redirect stderr to a file and check if the file is empty

Q1: any suggestion, how i can do the redirection, so it works? OR how can i read stderr instead of stdout using popen?
Q2: any other option other than creating a file?


Thinking 05-18-2006 02:36 AM

forget about it

system(); returns the exit status of the prog

All times are GMT -5. The time now is 02:48 PM.