Wrong exist status for os.system, os.poepen, etc.

P

Paolo Pantaleo

Subject: python2.4: Wrong exist status for os.system, os.poepen, etc.
Package: python2.4
Version: 2.4.4-2
Severity: normal



-- System Information:
Debian Release: 4.0
APT prefers testing
APT policy: (800, 'testing'), (70, 'stable'), (60, 'unstable')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-3-k7
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)

I send this to python-list also, so someone can tell if he/she can
(not) reproduce
the same behavior

The os.system() (but all the other funciont with similar behavior) reports
wrong exit status. I can reproduce the bug in the following way

create /tmp/x.c:

#include <stdlib.h>

int main(void){
exit(20);
}

$ cd /tmp
$ make x

$./x
$echo $?
20

$ python

give the following commands:
5120

the same for
5120


Greetings
PAolo



Versions of packages python2.4 depends on:
ii libbz2-1.0 1.0.3-6 high-quality block-sorting file co
ii libc6 2.3.6.ds1-10 GNU C Library: Shared libraries
ii libdb4.4 4.4.20-8 Berkeley v4.4 Database Libraries [
ii libncursesw5 5.5-5 Shared libraries for terminal hand
ii libreadline5 5.2-2 GNU readline and history libraries
ii libssl0.9.8 0.9.8c-4 SSL shared libraries
ii mime-support 3.39-1 MIME files 'mime.types' & 'mailcap
ii python2.4-minimal 2.4.4-2 A minimal subset of the Python lan

python2.4 recommends no packages.

-- no debconf information
 
P

Paul Boddie

The os.system() (but all the other funciont with similar behavior) reports
wrong exit status. I can reproduce the bug in the following way

I think you should look at some previous threads related to this
(obtained by searching Google Groups for "os.system exit status
code"):

"grabbing return codes from os.system() call"
http://groups.google.com/group/comp.lang.python/browse_frm/thread/efeab8a50ff16975/

"please help me understand os.system() result"
http://groups.google.com/group/comp.lang.python/browse_frm/thread/4a9ab6d5a609e9ca/

"os.system() << 8 ?"
http://groups.google.com/group/comp.lang.python/browse_frm/thread/f12ccab6389f482c/

In short, the returned code is actually a combination of two values,
and you need to extract the expected status code by shifting the
result 8 bits to the right. It may actually be more complicated than
that, but the man page for system ("man 3 system") explains this in
more detail.

Paul
 
P

PAolo

I think you should look at some previous threads related to this
(obtained by searching Google Groups for "os.system exit status
code"):

"grabbing return codes from os.system() call"http://groups.google.com/group/comp.lang.python/browse_frm/thread/efe...

"please help me understand os.system() result"http://groups.google.com/group/comp.lang.python/browse_frm/thread/4a9...

"os.system() << 8 ?"http://groups.google.com/group/comp.lang.python/browse_frm/thread/f12...

In short, the returned code is actually a combination of two values,
and you need to extract the expected status code by shifting the
result 8 bits to the right. It may actually be more complicated than
that, but the man page for system ("man 3 system") explains this in
more detail.

Paul

Sorry, for the mistake, I just missed the words "encoded in the format
specified for wait()" in the documentation of popen()

Thnx for the immediate answer
PAolo
 

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
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top