By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,223 Members | 1,371 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,223 IT Pros & Developers. It's quick & easy.

subprocess cwd keyword.

P: n/a
Dear All,

I would greatly appreciate a nudge in the right direction concerning
the use of cwd argument in the call function from subprocess module.

The setup is as follows:

driver.py <- python script
core/ <- directory
main <- fortran executable in the core directory
driver script generates some input files in the core directory. Main
should do its thing and dump the output files back into core.
The problem is, I can't figure out how to do this properly.

call("core/main") works but uses .. of core for input/output.

call("core/main",cwd="core") and call("main",cwd="core") both result in
File "driver.py", line 47, in <module>
main()
File "driver.py", line 40, in main
print "OUT", call("core/main", cwd="core")
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/subprocess.py", line 443, in call
return Popen(*popenargs, **kwargs).wait()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/subprocess.py", line 1051, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

perhaps if subprocess would indicate the abs path of the object in
question I could figure it out, but as is I'm lost.

--
Cheers, Ivan.


Oct 26 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ivan Vinogradov wrote:
Dear All,

I would greatly appreciate a nudge in the right direction concerning
the use of cwd argument in the call function from subprocess module.

The setup is as follows:

driver.py <- python script
core/ <- directory
main <- fortran executable in the core directory
driver script generates some input files in the core directory. Main
should do its thing and dump the output files back into core.
The problem is, I can't figure out how to do this properly.

call("core/main") works but uses .. of core for input/output.

call("core/main",cwd="core") and call("main",cwd="core") both result in
File "driver.py", line 47, in <module>
main()
File "driver.py", line 40, in main
print "OUT", call("core/main", cwd="core")
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/subprocess.py", line 443, in call
return Popen(*popenargs, **kwargs).wait()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/subprocess.py", line 1051, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

perhaps if subprocess would indicate the abs path of the object in
question I could figure it out, but as is I'm lost.

Perhaps you're looking for os.path.abspath?

import subprocess
import os

subdir = os.path.join(*[ os.path.dirname(os.path.abspath(__file__)),
"core" ])
print subdir

try:
retcode = subprocess.call(["./main"], cwd=subdir)
except:
raise

print retcode

--
Hope this helps,
Steven

Oct 27 '06 #2

P: n/a

Ivan Vinogradov wrote:
Dear All,

I would greatly appreciate a nudge in the right direction concerning
the use of cwd argument in the call function from subprocess module.

The setup is as follows:

driver.py <- python script
core/ <- directory
main <- fortran executable in the core directory
driver script generates some input files in the core directory. Main
should do its thing and dump the output files back into core.
The problem is, I can't figure out how to do this properly.

call("core/main") works but uses .. of core for input/output.

call("core/main",cwd="core") and call("main",cwd="core") both result in
[snip exception]

Usually current directory is not in the PATH on UNIX. Try
call("./main",cwd="core")

-- Leo

Oct 27 '06 #3

P: n/a
On 27-Oct-06, at 2:25 AM, Leo Kislov wrote:
>
Ivan Vinogradov wrote:
>...

call("core/main") works but uses .. of core for input/output.

call("core/main",cwd="core") and call("main",cwd="core") both
result in
[snip exception]

Usually current directory is not in the PATH on UNIX. Try
call("./main",cwd="core")

-- Leo
Thank you both Leo and Steven.
The solution was indeed calling "main" as "./main" once cwd was changed.

--
Cheers, Ivan.
Oct 27 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.