LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-18-2006, 02:11 AM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
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!

Last edited by Thinking; 05-18-2006 at 02:14 AM.
 
Old 05-18-2006, 02:36 AM   #2
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Original Poster
Rep: Reputation: 30
aaarrrgghh
forget about it

system(); returns the exit status of the prog
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 07:55 AM
Reopen the stdout and stderr rahul_kulkarni Programming 3 02-21-2005 06:55 AM
shell short question(stdout, stderr) blackzone Programming 4 11-11-2004 09:01 AM
Switch stdout between /dev/null and a file? gremlin2000 Linux - General 2 06-08-2004 07:12 AM
Switch stdout between /dev/null and a file? gremlin2000 Linux - Newbie 1 06-01-2004 10:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration