return codes from os.spawn

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Sep 17 15:16:11 EDT 2007


En Mon, 17 Sep 2007 08:17:22 -0300, Nirmal <nirmaljs at lasonindia.com>  
escribi�:

> Hi,
>
> When I try running java through os.spawnv with P_NOWAIT,  it returns the
> process id
>
>>>> os.spawnv(os.P_NOWAIT, '$JAVA_HOME/bin', ('java', '$JAVA_HOME/bin/java
> ex3178 true'))
> 19524
>
> then I removed the command line parameter in the java command to fail  
> ( it
> should throw an exception)  the process and ran it. This time also it
> returned the process id .
>
>>>> os.spawnv(os.P_NOWAIT, '$JAVA_HOME/bin', ('java', '$JAVA_HOME/bin/java
> ex3178'))
> 21947
>
>
> And I tried the same by using P_WAIT  and it returned the same exit code
>
>>>> os.spawnv(os.P_WAIT, '$JAVA_HOME/bin', ('java', '$JAVA_HOME/bin/java
> ex3178 true))
> 127
>>>> os.spawnv(os.P_WAIT, '$JAVA_HOME/bin', ('java', '$JAVA_HOME/bin/java
> ex3178'))
> 127

> please let me know how can we identify that the process is completed
> successfully or not ?

All your examples fail to execute your program. The second argument is the  
program being executed, not only the directory. Should be the same as the  
first element of `args`. And the individual arguments should be separated.

os.spawnv(os.P_WAIT, '$JAVA_HOME/bin/java', ['$JAVA_HOME/bin/java',  
'ex3178', 'true'])

In this case it's easier to use spawnl:

os.spawnl(os.P_WAIT, '$JAVA_HOME/bin/java', 'java', 'ex3178', 'true')


-- 
Gabriel Genellina




More information about the Python-list mailing list