I was wondering whether subprocess.call("if [ ! -d '{output}' ]; then mkdir -p {output}; fi",shell=True)
will be interpreted by sh
orzsh
instead of bash
in different server?
Anyone has ideas about this?
What should I do to make sure that it's interpreted by bash
?
- from Actual meaning of 'shell=True' in subprocess. If args is a string, the string specifies the command to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt.
From the docs: args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names).
By default, running subprocess. Popen with shell=True uses /bin/sh as the shell. If you want to change the shell to /bin/bash , set the executable keyword argument to /bin/bash .
I can say that you use subprocess. call() when you want the program to wait for the process to complete before moving onto the next process. In the case of subprocess. run() , the program will attempt to run all the processes at once, inevitably causing the program to crash.
http://docs.python.org/2/library/subprocess.html
On Unix with shell=True, the shell defaults to /bin/sh
Note that /bin/sh is often symlinked to something different, e.g. on ubuntu:
$ ls -la /bin/sh
lrwxrwxrwx 1 root root 4 Mar 29 2012 /bin/sh -> dash
You can use the executable
argument to replace the default:
... If shell=True, on Unix the executable argument specifies a replacement shell for the default /bin/sh.
subprocess.call("if [ ! -d '{output}' ]; then mkdir -p {output}; fi",
shell=True,
executable="/bin/bash")
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