How can I get the return value of a program that I launched from my program?
Printable View
How can I get the return value of a program that I launched from my program?
How are you calling the program from within a program?
popen(), system(), fork()/exec() ?
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
Which of these are you using to run your sub-program?
echo %errorlevel%
CreateProcess().
I dunno, something imaginative like reading the manual page for CreateProcess(), which has a handy "see also" section.
Obviously, this is the place to look for related functions, and gosh, there it is.
http://msdn.microsoft.com/library/de...odeprocess.asp
Does this mean thatCode:BOOL WINAPI GetExitCodeProcess(
HANDLE hProcess,
LPDWORD lpExitCode
);
is proper and valid too?Code:DWORD main()
Also, what happens when I try to get the exit code on a
program?Code:void main()
Thanks for link :), kinda stupid question thought I suppose, seeing how I have USED THE STUPID FUNC BEFORE! :( (Seeing the function prototype again brought it back.)
Why do you think you're not supposed to use void main()? ;)Quote:
Also, what happens when I try to get the exit code on a
program?Code:void main()
Yea, that's what I figured, but still, what would happen? Would the function fail? Or would it just return 0x00000000?
It's undefined!
True, but a really old compiler like turbo C++ or MSVC++6.0 would accept it as being a valid statement. Nowdays, most people put int main ( void )
Is DWORD main(void) valid too?
There is a saying on IRC channels...
TIAS!
(Try it and see!)
Nope.Quote:
Originally Posted by Dev-C++
Why is Win32 sooo... hung up on DWORD!?
> DWORD main()
int main is the portable answer.
It's just that a DWORD is capable of storing all possible integer values on that particular platform. I guess win32 GUI programs which begin with winmain() also return a DWORD as the exit status.
Besides, very few operating system shells can cope with process exit status values which exceed 8 bits, it isn't that much of a deal.
> Also, what happens when I try to get the exit code on a
<clint>Well punk, do you feel lucky</clint>