General discussion

  • Creator
    Topic
  • #2077806

    Return value of a Main function.

    Locked

    by amd_ghouse ·

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

All Comments

  • Author
    Replies
    • #3743873

      Return value of a Main function.

      by wayne m. ·

      In reply to Return value of a Main function.

      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.

    • #3738390

      Return value of a Main function.

      by karlww ·

      In reply to Return value of a Main function.

      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:\>

    • #3728185

      Return value of a Main function.

      by sriram_som ·

      In reply to Return value of a Main function.

      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

    • #3870071

      Return value of a Main function.

      by amd_ghouse ·

      In reply to Return value of a Main function.

      This question was auto closed due to inactivity

Viewing 3 reply threads