Help answer threads with 0 replies.
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 02-04-2009, 02:26 AM   #1
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){ stuff here....

Can anyone tell me where I am going wrong here ?

(Code is being compiled on ubuntu and debian)
Old 02-04-2009, 03:49 AM   #2
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

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

Original Poster
Rep: Reputation: 1
thanks a million


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 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

All times are GMT -5. The time now is 11:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration