result of system call

B

budgie

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
 
D

David B. Held

budgie said:
[...]
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
 
M

Moonlit

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

WW

Moonlit said:
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.
 
K

klaas

budgie said:
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
 
R

Ron Natalie

klaas said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top