Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-18-2006, 03:11 AM   #1
Registered: Oct 2003
Posts: 249

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


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

Original Poster
Rep: Reputation: 30
forget about it

system(); returns the exit status of the prog


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 08:55 AM
Reopen the stdout and stderr rahul_kulkarni Programming 3 02-21-2005 07:55 AM
shell short question(stdout, stderr) blackzone Programming 4 11-11-2004 10:01 AM
Switch stdout between /dev/null and a file? gremlin2000 Linux - General 2 06-08-2004 08:12 AM
Switch stdout between /dev/null and a file? gremlin2000 Linux - Newbie 1 06-01-2004 11:13 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:08 AM.

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