passing arguments from a python program to other while executing it with exec() or spawn() in LINUX

Peter Otten __peter__ at web.de
Thu Oct 16 09:57:25 CEST 2008


gaurav kashyap wrote:

> HI all,
> i have two python programs as 1.py and 2.py
> 
> 1.py
> import os
> import sys
> processID=os.spawnl(os.P_WAIT,'/usr/local/bin/python','python','/
> mywork/2.py ' + 'hi')
> 
> 2.py
> import sys
> domain= str(sys.argv[1] )
> print domain
> 
> IN LINUX
> while executing 1.py,the argument 'hi' is not passed to the 2.py and
> error message is displayed as :
> python: can't open file '/mywork/2.py'.

Did you cut and paste that? I would expect the message to be 

python: can't open file '/mywork/2.py hi'.

or similar, i. e. the script name is assumed to be '/mywork/2.py hi'. You
have to pass arguments to the 2.py script as separate arguments to
os.spawnl()

os.spawnl(os.P_WAIT,'/usr/local/bin/python','python','/mywork/2.py', 'hi')

Peter




More information about the Python-list mailing list