473,569 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

subprocess cwd keyword.

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.framewor k/Versions/2.5/lib/
python2.5/subprocess.py", line 443, in call
return Popen(*popenarg s, **kwargs).wait( )
File "/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framewor k/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
3 3584
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.framewor k/Versions/2.5/lib/
python2.5/subprocess.py", line 443, in call
return Popen(*popenarg s, **kwargs).wait( )
File "/Library/Frameworks/Python.framewor k/Versions/2.5/lib/
python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framewor k/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.abspat h(__file__)),
"core" ])
print subdir

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

print retcode

--
Hope this helps,
Steven

Oct 27 '06 #2

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4071
by: Stewart Midwinter | last post by:
this has me puzzled; I've created a small test app to show the problem I'm having. I want to use subprocess to execute system commands from inside a Tkinter app running under Cygwin. When I open a python interpreter and run my subprocess command, all is well. But when I run the same command from inside a Tkinter app, I'm getting errors.
3
5495
by: Darren Dale | last post by:
I'm a developer on the matplotlib project, and I am having trouble with the subprocess module on windows (Python 2.4.2 on winXP). No trouble to report with linux. I need to use _subprocess instead of pywin32, but my trouble exists with either option: import subprocess process = subprocess.Popen(, stderr=subprocess.STDOUT,...
0
1374
by: I. Myself | last post by:
I want my Python program to invoke a compiled C program, and capture the text output. Here's a fragment from a program that works, using subprocess.Popen: p = Popen(execName, stdout=PIPE) while(1): line = p.stdout.readline() # get next line outfile.write(line) (Then I test for a certain unique phrase in line, and then break if it occurs)
5
14303
by: Grant Edwards | last post by:
I'm trying to use the py-gnuplot module on windows, and have been unable to get it to work reliably under Win2K and WinXP. By default, it uses popen(gnuplotcmd,'w'), but in some situations that consistently gets an "invalid operand" IOError when write() is called on the pipe. So I switched to subprocess. It works fine when executed...
2
9141
by: revenant81 | last post by:
I'm writing a program which has to execute a command, get its output and show it on a treeview. This command runs for a very long time. I want to end the execution of the command when the user closes my application. Right now I'm using an object my_child of type subprocess.Popen to execute the command, inside a thread with an infinite loop...
9
6469
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This hangs at this point. How should I handle these kind of commands (ping 127.0.0.1) with
10
2560
by: JD | last post by:
Hi, I want send my jobs over a whole bunch of machines (using ssh). The jobs will need to be run in the following pattern: (Machine A) (Machine B) (Machine C) Job A1 Job B1 Job C1 Job A2 Job B2 etc
7
4715
by: timw.google | last post by:
Hi I want to write a python script that runs rsync on a given directory and host. I build the command line string, but when I try to run subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or os.system(cmd), I get prompted for my login password. I expected this, but when I try to give my password, it's echoed back to the terminal...
12
4515
by: bhunter | last post by:
Hi, I've used subprocess with 2.4 several times to execute a process, wait for it to finish, and then look at its output. Now I want to spawn the process separately, later check to see if it's finished, and if it is look at its output. I may want to send a signal at some point to kill the process. This seems straightforward, but it...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.