Output program return

How can I make this:

- I start my program
- my program starts another program (program2)
- program 2 runs and returns a value
- my program prints that value

I'm a beginner, I'd like to know if this is possible and how I can achieve it.


C++ on Windows with CodeBlocks
You do that by using CreateProcess() and waiting on the process handle using WaitForSingleObject(). Once it is done waiting, you call GetExitCodeProcess() to obtain the return value of the process and store it in a DWORD variable. Then you can easily print it out.
Thank you
How do I use CreateProcess()?

 
CreateProcess("myprocess.exe");


will it look into the main executable's folder and find 'myprocess.exe' and start it?
Do I have to include any libraries like stdlib.h?
Google up "createprocess" and read the documentation of the function in the MSDN Online website. It comes complete with samples.

You will also see the header, LIB and DLL files that include this function at the bottom. Since you mention stdlib.h, I am only guessing you have never programmed for Windows in the past, so it would be best if you read a tutorial on the matter first.
Topic archived. No new replies allowed.