subprocess returncode windows

Christian Heimes lists at
Tue Dec 16 19:50:09 CET 2008

Andrew schrieb:
> Hello,
> I'm running into a strange situation with getting incorrect
> returncodes / exit status from python 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"
> ----------------------
> 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

Don't use shell=True! Instead use a list of arguments without shell=True:

call(["c:/glassfish/bin/asadmin.bat", "list-system-properties", "--host
mydomain", "--port 4848", "--user admin", "server-01"])

That should solve your quoting issues on Windows and fix your code.
shell=True is considered evil and should be avoided whenever possible.


More information about the Python-list mailing list