Error while executing with subprocess
<p>I'm trying to execute a shell command via Python code, but I'm not capable to understand why it is failing.</p>

<p>When printing the command and pasting it to the shell to try executing it directly works perfectly fine, that's the strange part.</p>

<p>From Python I'm getting the following:</p>

<pre><code>/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `/DATA/NGS/ngs_software/bioinfoSoftware/bwa_current/bwa mem ... --threads 4 -T /tmp/samTemp -'
</code></pre>

<p>Is there anything I'm missing? My code looks like this, where 'cmd' is the string with the command. The OS is a CentOS with a bash shell:</p>

<pre><code>process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
out = process.stdout.readline()
out = out.decode("utf-8").strip('\n')
</code></pre>

<p>Your command contains a process substitution, but <code>Popen</code> runs its command using <code>/bin/sh</code>. When run as <code>/bin/sh</code>, though, <code>bash</code> does not allow process substitutions. You can explicitly request that the command be run with <code>bash</code> using the <code>executable</code> option.</p>

<pre><code>process = subprocess.Popen(cmd, shell=True, executable='/bin/bash', stdout=subprocess.PIPE)
</code></pre>

python bash shell