0

the following command line works and gives correct results

$ python maps2.py -i=/media/babak/LaCie/necessary/visualisation/CMIP3_Babak/Temperature/bccr_bcm2_0 -o=temp/CMIP3 -p=temp_001

but when the exact command is called, using the following subprocess module:

run=subprocess.Popen([sys.executable, 'maps2.py -i=/media/babak/LaCie/necessary/visualisation/CMIP3_Babak/Temperature/bccr_bcm2_0 -o=temp/CMIP3 -p=temp_001' ])

it gives the following error:

/usr/bin/python: can't open file 'maps2.py -i=/media/babak/LaCie/necessary/visualisation/CMIP3_Babak/Temperature/bccr_bcm2_0 -o=temp/CMIP3 -p=temp_001': [Errno 2] No such file or directory

what's the reason? the commands are exactly the same. Thank you for your help.

0

2 Answers 2

2

When using subprocess.Popen() the first argument should be a list with a separate entry for each argument to the process you want to run:

run=subprocess.Popen([sys.executable, 'maps2.py', '-i=/media/babak/LaCie/necessary/visualisation/CMIP3_Babak/Temperature/bccr_bcm2_0', '-o=temp/CMIP3', '-p=temp_001' ])

What you currently have would be the equivalent to running the following on the command line:

python 'maps2.py -i=/media/babak/LaCie/necessary/visualisation/CMIP3_Babak/Temperature/bccr_bcm2_0 -o=temp/CMIP3 -p=temp_001'
Sign up to request clarification or add additional context in comments.

Comments

1

In addition to F.J.'s answer, you can easily split the name of the executable from the arguments with shlex.split

mapsCommand = 'maps2.py -i=/media/babak/LaCie/necessary/visualisation/CMIP3_Babak/Temperature/bccr_bcm2_0 -o=temp/CMIP3 -p=temp_001'
fullCommand = [sys.executable]
fullCommand.extend(shlex.split(mapsCommand))
run=subprocess.Popen(fullCommand)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.