![]() |
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 |
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 |
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 |
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 |
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 |
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.