Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   result of system call (http://www.velocityreviews.com/forums/t278268-result-of-system-call.html)

budgie 10-09-2003 09:43 AM

result of system call
 
Hi there,

I'm using the system() function to call a program but would like to
get the result of this operation.

system returns an int depending on weather the command was executed
successfully of not.

How can I get a string -- or array of strings with the output of the
camming line application instead?

Thanks

Karl

David B. Held 10-09-2003 09:55 AM

Re: result of system call
 
"budgie" <larrylarrigan@yahoo.com> wrote in message
news:75511ff7.0310090143.1cafb322@posting.google.c om...
> [...]
> How can I get a string -- or array of strings with the output of
> the camming line application instead?


You would need to redirect the output of the application.
On many systems, there is a fork() function, or something
similar. In this way, your program can call another process
and control several features, such as the I/O.

Dave



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003



Moonlit 10-09-2003 10:42 AM

Re: result of system call
 
Hi,

Use
popen( "command", "r" );

then read from the returned descriptor. This method is one way either you
read or write, but it is less code than fork.

Regards, Ron AF Greve.



"budgie" <larrylarrigan@yahoo.com> wrote in message
news:75511ff7.0310090143.1cafb322@posting.google.c om...
> Hi there,
>
> I'm using the system() function to call a program but would like to
> get the result of this operation.
>
> system returns an int depending on weather the command was executed
> successfully of not.
>
> How can I get a string -- or array of strings with the output of the
> camming line application instead?
>
> Thanks
>
> Karl




WW 10-09-2003 02:46 PM

Re: result of system call
 
Moonlit wrote:
> Hi,
>
> Use
> popen( "command", "r" );
>
> then read from the returned descriptor. This method is one way either
> you read or write, but it is less code than fork.


Neither popen, nor fork is a standard C or C++ function. They are POSIX
functions, off-topic here. But that is not the point: since they aren't C
and C++ functions it is nice to mention that fact once you post them into a
C++ newsgroup.

--
WW aka Attila



klaas 10-09-2003 07:34 PM

Re: result of system call
 
budgie wrote:
> Hi there,
>
> I'm using the system() function to call a program but would like to
> get the result of this operation.
>
> system returns an int depending on weather the command was executed
> successfully of not.
>
> How can I get a string -- or array of strings with the output of the
> camming line application instead?
>
> Thanks
>
> Karl

maybe
char * d << system("yukk.exe");
might work
but then it probably will not
but you could make it work with:
my_string x << system("yukk.exe");
but probably not, because standard out is standard out


Ron Natalie 10-09-2003 07:38 PM

Re: result of system call
 

"klaas" <jan@zonnet.ru> wrote in message news:UKihb.11381$732.1216351@zonnet-reader-1...

> maybe
> char * d << system("yukk.exe");
> might work
> but then it probably will not
> but you could make it work with:
> my_string x << system("yukk.exe");
> but probably not, because standard out is standard out


System doesn't return strings. System returns a single int.
If the argument is other than a null pointer, the value of this
single int is implementation-defined.

It's not a bunch of strings reflecting the output of the command
invoked in any case.

You will have to do this in a system dependent fashion. If you
are on a UNIX/POSIX system, try popen.




All times are GMT. The time now is 07:13 PM.

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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57