Discussion Locked
0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do you trap the return value of a main function in C or C++
7 replies
by wayne m.
Main() returns to the OS. You will have to use OS specific scripting to read the return value. Another option is to call your program from another program using spawn(). This function returns the exit status of the called program to the calling program. I believe spawn() or a variant is available on both Windows and UNIX platforms.
by amd_ghouse
The question was auto-closed by TechRepublic
by karlww
If you are using NT, check the value of ERRORLEVEL. The following example assumes you are calling a program called MYCPROG.EXE and shows the value returned by MAIN (assuming of course it is 0);
C:\>mycprog.exe
C:\>echo %ERRORLEVEL%
0
C:\>
by amd_ghouse
The question was auto-closed by TechRepublic
by sriram_som
In case of unix, you can write a small shell script one like the below to trap/find the return value of the executable(that contain main):
#! /bin/sh
echo $?
Hope this helps
by amd_ghouse
The question was auto-closed by TechRepublic
by amd_ghouse
This question was auto closed due to inactivity
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending
0 helpful
5 replies
1 helpful
3 replies
0 helpful
1 reply
0 helpful
1 reply
Question Unanswered
PDF vs HTML
0 helpful
0 replies