Reputation: 23
I'm trying to execute a shell command via Python code, but I'm not capable to understand why it is failing.
When printing the command and pasting it to the shell to try executing it directly works perfectly fine, that's the strange part.
From Python I'm getting the following:
/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 -'
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:
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
out = process.stdout.readline()
out = out.decode("utf-8").strip('\n')
Upvotes: 1
Views: 1758
Reputation: 530853
Your command contains a process substitution, but Popen
runs its command using /bin/sh
. When run as /bin/sh
, though, bash
does not allow process substitutions. You can explicitly request that the command be run with bash
using the executable
option.
process = subprocess.Popen(cmd, shell=True, executable='/bin/bash', stdout=subprocess.PIPE)
Upvotes: 2