Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Extracting output from system(3) call (http://www.velocityreviews.com/forums/t442729-extracting-output-from-system-3-call.html)

v4vijayakumar 05-13-2006 05:46 AM

Extracting output from system(3) call
 
is there any standard way to extract output from system(3) function?
TIA.


v4vijayakumar 05-13-2006 06:01 AM

Re: Extracting output from system(3) call
 
if possible to use pipe(2) how could file descriptor can be derived
from file pointer, FILE *. TIA.


v4vijayakumar 05-13-2006 06:30 AM

Re: Extracting output from system(3) call
 
am going to use

system("ls > /tmp/t");


Robert Harris 05-13-2006 08:27 AM

[OT]Re: Extracting output from system(3) call
 
v4vijayakumar wrote:
> is there any standard way to extract output from system(3) function?
> TIA.
>


<OT>
In a Posix system, use popen(3) instead
</OT>

Robert

Keith Thompson 05-13-2006 09:14 AM

Re: Extracting output from system(3) call
 
"v4vijayakumar" <v4vijayakumar@yahoo.com> writes:
> is there any standard way to extract output from system(3) function?
> TIA.


The C standard doesn't provide any way to do this, but your
implementation might. Try a system-specific newsgroup.

But first, please read <http://cfaj.freeshell.org/google/>.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

=?ISO-8859-1?Q?Martin_J=F8rgensen?= 05-13-2006 01:40 PM

Re: [OT]Re: Extracting output from system(3) call
 
Robert Harris wrote:
> v4vijayakumar wrote:
>
>>is there any standard way to extract output from system(3) function?
>>TIA.
>>

>
>
> <OT>
> In a Posix system, use popen(3) instead
> </OT>


BTW: What is Posix???


Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk

SM Ryan 05-13-2006 02:46 PM

Re: Extracting output from system(3) call
 
"v4vijayakumar" <v4vijayakumar@yahoo.com> wrote:
# is there any standard way to extract output from system(3) function?

You have to save the output to a file within the command line,
and then open the file subsequently.
For example on unix, you can do something like
if (system("cat gloober/* >fripper")!=0) error(...);
FILE *fripper = fopen("fripper","r");
...
fclose(fripper);

POSIX systems also provide popen/pclose.
FILE *fripper = popen("cat gloober/*","r");
...
if (pclose(fripper)!=0) error(...);

--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.

Mike Wahler 05-13-2006 04:52 PM

Re: [OT]Re: Extracting output from system(3) call
 

"Martin Jørgensen" <unoder.spam@spam.jay.net> wrote in message
news:084hj3-hpk.ln1@news.tdc.dk...
> Robert Harris wrote:
>> v4vijayakumar wrote:
>>
>>>is there any standard way to extract output from system(3) function?
>>>TIA.
>>>

>>
>>
>> <OT>
>> In a Posix system, use popen(3) instead
>> </OT>

>
> BTW: What is Posix???


http://en.wikipedia.org/wiki/POSIX

-Mike



v4vijayakumar 05-15-2006 08:37 AM

Re: Extracting output from system(3) call
 
It seems that there is another way.

fclose (stdout);
stdout = fopen ("standard-output-file", "w");

system("ls");

/* process output file here */


Flash Gordon 05-15-2006 09:45 AM

Re: Extracting output from system(3) call
 
v4vijayakumar wrote:
> It seems that there is another way.


Another way to do what? Google is most definitely *not* Usenet, just an
interface that dupes people in to making incorrect assumptions. Read
http://clc-wiki.net/wiki/Intro_to_clc and provide context in future.

> fclose (stdout);
> stdout = fopen ("standard-output-file", "w");
>
> system("ls");
>
> /* process output file here */


I've got no idea what you think the above will do, but I doubt it will
actually do what you think. For a start, there is no guarantee that
changing stdout within a program will affect where the output of a
program invoked using system goes.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc


All times are GMT. The time now is 08:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.