954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

system function in c++

can anyone give me more info on the system command? It allows you to execute dot exe programs from your code.

I am in particular looking for return values. Can one get the system function to let the called program write its output to a variable instead of writting it in the command window?

quintoncoert
Posting Whiz in Training
266 posts since May 2007
Reputation Points: 160
Solved Threads: 3
 

>> Can one get the system function to let the called program write its output to a
>> variable instead of writting it in the command window?
Yes. But AFAIK it would be useless because that variable would be part of the shell (assuming you're on Unix) that executes teh cmd and this shell will be destroyed when system returns.
It might be better if you would make the program write the return code to a flat file, which you would be able to read later.

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

you can make it write the output to a file and then your program will have access to it. Or instead of system() use pipe() and your program can read the program's output into a variable such as a character buffer.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You