subprocess.call(["/home/blah/trunk/blah/run.sh", "/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?
To change directories, use the command cd followed by the name of the directory (e.g. cd downloads ). Then, you can print your current working directory again to check the new path.
We can also execute an existing a bash script using Python subprocess module.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With