subprocess returncode windows

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Dec 16 18:11:12 EST 2008


En Tue, 16 Dec 2008 17:21:35 -0200, Andrew <andrew.replogle at gmail.com>  
escribió:
> On Dec 16, 12:50 pm, Christian Heimes <li... at cheimes.de> wrote:
>> Andrew schrieb:
>>
>> > 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
>
> I've removed shell=True, unfortunately, if I structure the call like:
>
> call(["c:/glassfish/bin/asadmin.bat", "list-system-properties", "--
> host
> mydomain", "--port 4848", "--user admin", "server-01"])
>
> It doesn't seem to recognize any arguments after list-system-
> properties.

Should be:

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

*Every* argument should be an item in the list (your way, "--port 4848"  
becomes a single argument, not two: option plus value)
(This is independent of your other issue)

> If I structure it like:
>
> call("c:/glassfish/bin/asadmin.bat "+"list-system-properties --host
> mydomain --port 4848 --user admin server-01")
>
> Then it executes correctly but still gives invalid returncode of 0
> when it fails instead of 1.

A similar example works fine for me:

C:\temp>type ret.c
#include <stdlib.h>

int main(int argc, char* argv[])
{
   return atoi(argv[1]);
}

C:\temp>ret 5

C:\temp>echo %errorlevel%
5

C:\temp>type testret.bat
ret %1

C:\temp>testret 3

C:\temp>ret 3

C:\temp>echo %errorlevel%
3

C:\temp>type testret.py
 from subprocess import call
ret = call(["testret.bat", "42"])
print "testret.bat exit code =", ret

C:\temp>python testret.py

C:\temp>ret 42
testret.bat exit code = 42

C:\temp>python -V
Python 2.6

C:\temp>ver

Microsoft Windows XP [Versión 5.1.2600]

-- 
Gabriel Genellina




More information about the Python-list mailing list