Unix Programming - Captureing stdout and useing it elsewhere.

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2006 > Captureing stdout and useing it elsewhere.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Captureing stdout and useing it elsewhere.
nori

2006-06-26, 7:20 pm

Okay, I am working on a program. In the program there will be
something along the lines of

system(whatever)

This is a GUI program, so I want a way to see what would be printed to
the screen. What I want to know is, is there anyway that I can capture
stdout to a variable, not a file. For instance I know that this does
not exist but what I mean is:

get_stdout_to_var(system("echo hello world"), stdout_var);

Of course stdout_var would be of type (char *). So I guess what I'm
asking is: is this possible?
Nori

Paul Pluzhnikov

2006-06-26, 7:20 pm

"nori" <noridotjabi@gmail.com> writes:

> What I want to know is, is there anyway that I can capture
> stdout to a variable, not a file.


Do "man popen". Once you have a FILE* handle, you can read its
contents into any buffer you like.

Note that even though you get a FILE* handle, there is no actual
file on disk to which this data will ever be written.

> So I guess what I'm asking is: is this possible?


Possible, and quite frequently done.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com