General discussion

Locked

Return value of a Main function.

By amd_ghouse ·
How do you trap the return value of a main function in C or C++

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Return value of a Main function.

by Wayne M. In reply to Return value of a Main f ...

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.

Collapse -

Return value of a Main function.

by amd_ghouse In reply to Return value of a Main f ...

The question was auto-closed by TechRepublic

Collapse -

Return value of a Main function.

by karlww In reply to Return value of a Main f ...

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>

Collapse -

Return value of a Main function.

by amd_ghouse In reply to Return value of a Main f ...

The question was auto-closed by TechRepublic

Collapse -

Return value of a Main function.

by sriram_som In reply to Return value of a Main f ...

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

<your executable>
echo $?

Hope this helps

Collapse -

Return value of a Main function.

by amd_ghouse In reply to Return value of a Main f ...

The question was auto-closed by TechRepublic

Collapse -

Return value of a Main function.

by amd_ghouse In reply to Return value of a Main f ...

This question was auto closed due to inactivity

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums