LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   redirecting stdout to /dev/null and stderr to stdout? (https://www.linuxquestions.org/questions/programming-9/redirecting-stdout-to-dev-null-and-stderr-to-stdout-445958/)

Thinking 05-18-2006 02:11 AM

redirecting stdout to /dev/null and stderr to stdout?
 
hiho@ll

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

how i try it:
Code:

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

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?

thx@ll!

Thinking 05-18-2006 02:36 AM

aaarrrgghh
forget about it

system(); returns the exit status of the prog


All times are GMT -5. The time now is 10:58 PM.