subprocess.call(["/home/blah/trunk/blah/run.sh",开发者_Go百科 "/tmp/ad_xml", "/tmp/video_xml"])
I do this. However, inside my run.sh, I have "relative" paths. So, I have to "cd" into that directory, and then run the shell script. How do I do that?
Use the cwd
argument to subprocess.call()
From the docs here: http://docs.python.org/library/subprocess.html
If
cwd
is not None, the child’s current directory will be changed tocwd
before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative tocwd
.
Example:
subprocess.call(["/home/blah/trunk/blah/run.sh", "/tmp/ad_xml", "/tmp/video_xml"], cwd='/tmp')
Well, you could use subprocess.Popen with Shell = True and cwd = "Your desired working directory"
EDIT: It appears that call has the same arguments so just setting a cwd argument would work:
subprocess.call(["/home/blah/trunk/blah/run.sh", "/tmp/ad_xml", "/tmp/video_xml"], cwd="PATH")
You can supply your working directory like this:
subprocess.call(["/home/blah/trunk/blah/run.sh", "/tmp/ad_xml", "/tmp/video_xml"], cwd="/home/blah/trunk/blah")
os.chdir(path)
http://docs.python.org/library/os.html#os.chdir
精彩评论