subprocess returncode windows

Andrew andrew.replogle at gmail.com
Tue Dec 16 13:30:48 EST 2008


Hello,

I'm running into a strange situation with getting incorrect
returncodes / exit status from python subprocess.call. I'm using a
python script (runtime 2.6.1 on windows) to automate the deploy of
java applications to glassfish application server. Below is an example
of using a subprocess call to test the success / failure of the
glassfish CLI tool "asadmin"

Example.py:
----------------------
import sys
from subprocess import *

try:
    retcode = call("c:/glassfish/bin/asadmin.bat " + "list-system-
properties --host mydomain --port 4848 --user admin server-01",
shell=True)
    if retcode < 0:
        print >>sys.stderr, "Child was terminated by signal", -retcode
    else:
        print >>sys.stderr, "Child returned", retcode
except OSError, e:
    print >>sys.stderr, "Execution failed:", e
----------------------

However, when I execute it, it gets the same returncode whether it
fails or succeeds (0).

---------------------
C:\>python z:\bin\example.py
Please enter the admin password> ***Enters Good Password***
IIOP_SSL_MUTUALAUTH_PORT=33920
JMX_SYSTEM_CONNECTOR_PORT=38686
IIOP_LISTENER_PORT=33700
IIOP_SSL_LISTENER_PORT=33820
HTTP_LISTENER_PORT=38080
AJP_INSTANCE_NAME=WebReporting-01
HTTP_SSL_LISTENER_PORT=38181
JMS_PROVIDER_PORT=37676
AJP_PORT=18009
Command list-system-properties executed successfully.
Child returned 0

C:\>python z:\bin\example.py
Please enter the admin password>***Enters BAD PASSWORD***
Invalid user or password
CLI137 Command list-system-properties failed.
Child returned 0

C:\>
------------------------------------------------

When I execute this manually from the cmd.exe and I check the
%errorlevel% it returns the correct levels:

-----------------------------------------------
C:\>c:\glassfish\bin\asadmin.bat list-system-properties --host
mydomain --port 4848 --user admin server-01
Please enter the admin password>***GOOD PASSWORD***
IIOP_SSL_MUTUALAUTH_PORT=33920
JMX_SYSTEM_CONNECTOR_PORT=38686
IIOP_LISTENER_PORT=33700
IIOP_SSL_LISTENER_PORT=33820
HTTP_LISTENER_PORT=38080
AJP_INSTANCE_NAME=WebReporting-01
HTTP_SSL_LISTENER_PORT=38181
JMS_PROVIDER_PORT=37676
AJP_PORT=18009
Command list-system-properties executed successfully.

C:\>echo %errorlevel%
0

C:\>c:\glassfish\bin\asadmin.bat list-system-properties --host
mydomain --port 4848 --user admin server-01
Please enter the admin password>***BAD PASSWORD***
Invalid user or password
CLI137 Command list-system-properties failed.

C:\>echo %errorlevel%
1

C:\>
-------------------------------------

I'm guessing that returncode isn't the same thing as exit status?  Is
there a way to get exit status using a subprocess function instead of
returncode? Is this the right way to go about this?

Thanks for any direction / advice you can provide.

Andrew



More information about the Python-list mailing list