LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 02: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, 03:49 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
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, 04:09 AM   #3
mshindo
LQ Newbie
 
Registered: Jun 2008
Posts: 8

Original Poster
Rep: Reputation: 1
thanks a million
 
  


Reply



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 08:10 PM
Input/output errors at start-up fof3 Linux - Newbie 3 02-13-2006 08:52 PM
popen output not appear dimsh Programming 4 10-22-2005 02:56 AM
overcoming input/output errors heiseltc Linux - General 0 02-26-2003 12:29 PM
CHMOD and Input/Output errors lachlan Linux - General 3 12-30-2002 04:11 AM

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

All times are GMT -5. The time now is 05:51 AM.

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