popen catching output and errors


 
Thread Tools Search this Thread
Top Forums Programming popen catching output and errors
# 1  
Old 02-04-2009
popen catching output and errors

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
# 2  
Old 02-04-2009
It has nothing to do with your C++ code. command.str() needs to look like this:
Code:
some command 2&>1

This redirects stderr to stdout, so both streams will be merged and returned as stdout to your program.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Suppressing errors from command output

Hi, When I run the command "print_manifest | grep "Main Memory", I get the note : # /opt/ignite/bin/print_manifest | grep "Main Memory" NOTE: Could not read the /etc/resolv.conf file. Main Memory: 196498 MB # How do I suppress the part : NOTE: Could not read the... (4 Replies)
Discussion started by: anaigini45
4 Replies

2. Programming

Printing Popen Output Using Windows 7

Hi Guys, I am new to python and I am trying to print ouput of Popen on my text screen (tkinter gui). I was able to make it work on Linux with this code: Linux: Working def PrintSomething2(): outputdata = commands.getstatusoutput("sudo fping -f host.list") for i in outputdata:... (2 Replies)
Discussion started by: tattoostreet
2 Replies

3. Programming

Python tar script; no errors; no output

This script produces no errors. It also does not produce an output file. Any ideas? #!/usr/bin/python import tarfile output_filename = 'etc.tar' source_dir = '/etc/' #To build a .tar.gz for an entire directory tree: def make_tarfile(output_filename, source_dir): with... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

4. Shell Programming and Scripting

sending mail in perl.. No errors and also no output

Hi folks, I am trying to send an email in Perl script with the below code. I have written the code in Padre IDE and installed all the required modules(Mail::Sendmail) and executed the code. It is neither showing errors nor giving the output. I havnt received an mail after running the below... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. HP-UX

errors from output /usr/bin/last

for ga016dgf -> /usr/bin/last | cut -c1-3 Invalid record size. Unable to continue ... any ideas? running on ga016dgf -> uname -a HP-UX ga016dgf B.11.31 U ia64 1246079591 unlimited-user license thank you. Video tutorial on how to use code tags in The UNIX and Linux Forums. (4 Replies)
Discussion started by: Bill L.
4 Replies

6. Shell Programming and Scripting

Need help redirecting output to a file including errors

Need help redirecting output to a file including errors if any,I have 2 script namely push.ksh and run.ksh, I'm scp'ing push.ksh to another server and executing remotely via run.ksh, the script run.ksh runs locally but does not capture any errors in "servername.out" file (I tried testing various... (10 Replies)
Discussion started by: mbak
10 Replies

7. Shell Programming and Scripting

Catching errors

Hi, I'm writing a scheduling script which will co-ordinate the launching of scripts. This script is scheduling based on an input file, and launches the appropriate scripts at the right times. The only issue I'm having is: - if a script dies, or even has a syntax error, I want to catch... (1 Reply)
Discussion started by: GoldenEye4ever
1 Replies

8. Shell Programming and Scripting

catching some errors

I need to find a way to keep a running tally of how many times events or actions occur. Say if a user is prompted to make inputs of 1 or 2, I want it to keep track of how many times 1 was entered, and how many times 2 was entered. Thanks for your help (5 Replies)
Discussion started by: bebop1111116
5 Replies

9. Programming

ld: fatal: Symbol referencing errors. No output written to SNX

Hi all, I am getting the following error when I try to do a build of a product. I dont have the dependencies of the binaries involved in the build and thats the reason I was not able to find which library to add or to proceed to the next step to solve the reference problem. Undefined ... (1 Reply)
Discussion started by: jerryragland
1 Replies

10. UNIX for Dummies Questions & Answers

redirecting output, including errors

what's the proper syntax to redirect output, including all errors? ls -la > direct.list makes out put file direct.list but if i'm running a script and i want to include the errors, would i type something like: myscript.scr 2> out_list.txt or will that get the errors only? (1 Reply)
Discussion started by: kymberm
1 Replies
Login or Register to Ask a Question