Program return value ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Marshall

    Program return value ?

    Hi all, I'm trying to get the exit code of a program
    I want to exec in a python script in a portable manner.

    I've read that both os.system and os.spawnl are not a
    portable solution.

    I tried the os.popen() function and I got the program's exit
    code with the close() method.

    p=os.popen("ret urn_a_exit_code .sh")
    retval=p.close( )

    The only problem is that it doesn't return negative values.

    What is your experience with that ?

    Thanks in advance.

  • Hallvard B Furuseth

    #2
    Re: Program return value ?

    George Marshall wrote:
    [color=blue]
    > Hi all, I'm trying to get the exit code of a program
    > I want to exec in a python script in a portable manner.
    > (...)
    > The only problem is that it doesn't return negative values.[/color]

    On a Unix system, the exit status from a program is one byte, which on
    8-bit systems can have values from 0 to 255. So if the program does
    exit(-1), the exit status is (unsigned char)-1 == 255.

    I don't know how this works on other operating system, but in any case I
    imagine your problem is with the possible range of the exit status, not
    with python. Maybe your program should write a value to stdout (or some
    other file) instead, so python could read the number.

    --
    Hallvard

    Comment

    Working...