Grabbing return value from a program

This is a discussion on Grabbing return value from a program within the Tech Board forums, part of the Community Boards category; Hi all, I am working on a project in which I need to run a program (I don't have the ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    6

    Question Grabbing return value from a program

    Hi all,
    I am working on a project in which I need to run a program (I don't have the code, only the executable) and as programme terminates, I need to recive the return value it emits with its return statement.
    Plz help me....
    Thanks in advance...

    Scorpio

  2. #2
    .
    Join Date
    Nov 2003
    Posts
    307
    If the OS is Unix the return value is in a shell variable named -- $?

    I think we need a little more information, please.

  3. #3
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by scorpio_IITR
    I am working on a project in which I need to run a program (I don't have the code, only the executable) and as programme terminates, I need to recive the return value it emits with its return statement.
    It's not a C question. It's a system shell question...
    Emmanuel Delahaye

    "C is a sharp tool"

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Off to the tech forum we go....

    In a Windows console, use %ERRORLEVEL%

    Type "help if" and you might get something that contains this:
    Code:
     %ERRORLEVEL% will expand into a string representation of
     the current value of ERRORLEVEL, provided that there is not already
     an environment variable with the name ERRORLEVEL, in which case you
     will get its value instead.  After running a program, the following illustrates ERRORLEVEL use:
     
     	goto answer%ERRORLEVEL%
     	:answer0
     	echo Program had return code 0
     	:answer1
     	echo Program had return code 1
     
     You can also using the numerical comparisons above:
     
     	IF %ERRORLEVEL% LEQ 1 goto okay
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    6

    Question Sorry for missing information

    I am working in Linux, I wanted my C programme to pickup the return value directly. I am currently using shell script to do the same thing, recive the value and generate a kill signal if not equal to zero.....

    I want to eliminate dependence on shell script....

    Help Plz....

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Post some code showing what you're trying to achieve.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    int return_value = system(my_program);
    printf("The return value from my program was %d\n", return_value);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 09:55 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  3. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  4. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  5. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21