LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-04-2009, 03:26 AM   #1
mshindo
LQ Newbie
 
Registered: Jun 2008
Posts: 8

Rep: Reputation: 1
catching output and errors with popen c++


I have code which at the moment only catches the command/program output if the program runs correctly, which is a small problem as I would like to capture everything from stdout inclusive of errors

FILE *fp;
fp = popen(command.c_str(), "r");
while(fgets(cbuf, 1024, fp) != NULL){
.....do stuff here....
}
pclose(fp);

Can anyone tell me where I am going wrong here ?

(Code is being compiled on ubuntu and debian)
Regards
Michael
 
Old 02-04-2009, 04:49 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
The simplest way to do this is to make sure that the command string ends with these characters:
Code:
2>&1
 
Old 02-04-2009, 05:09 AM   #3
mshindo
LQ Newbie
 
Registered: Jun 2008
Posts: 8

Original Poster
Rep: Reputation: 1
thanks a million
 
  


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
Disable errors output to console Tushar Pednekar Linux - Software 2 07-17-2006 09:10 PM
Input/output errors at start-up fof3 Linux - Newbie 3 02-13-2006 09:52 PM
popen output not appear dimsh Programming 4 10-22-2005 03:56 AM
overcoming input/output errors heiseltc Linux - General 0 02-26-2003 01:29 PM
CHMOD and Input/Output errors lachlan Linux - General 3 12-30-2002 05:11 AM


All times are GMT -5. The time now is 03:36 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration