Program return value ?

  • Thread starter George Marshall
  • Start date
G

George Marshall

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("return_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.
 
H

Hallvard B Furuseth

George said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,490
Latest member
Finplus

Latest Threads

Top