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

G

gaurav kashyap

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'.If i execute the program from
shell like:
python 2.py hi,then it works fine


IN WINDOWS
this is working fine

PLEASE HELP.
thanks
gaurav
 
P

Peter Otten

gaurav said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top