No, you can't change what shell os.system()
uses, because that function makes a call to the system()
C function, and that function has the shell hardcoded to /bin/sh
.
Use the subprocess.call()
function instead, and set the executable
argument to the shell you want to use:
subprocess.call("command", shell=True, executable='/bin/bash')
From the Popen()
documentation (which underlies all subprocess
functionality):
On Unix with shell=True
, the shell defaults to /bin/sh
. If args is a string, the string specifies the command to execute through the shell.
and
If shell=True
, on Unix the executable argument specifies a replacement shell for the default /bin/sh
.
If you can't use subprocess
and you can't use pipes, you'd be limited to the os.spawn*()
functions; set mode to os.P_WAIT
to wait for the exit code:
retval = os.spawnl(os.P_WAIT, '/bin/bash', '-c', 'command')