How can I get the output of a Python subprocess command that contains a pipe?
问题 I have: cmd_array = ['head', '-n', str(source_noise_end), "data/noise/" + source + '_16k.dat', '|', 'tail', '-' + str(source_noise_start)] source_noise = subprocess.check_output(cmd_array) The command is valid when I type it into Linux. I get subprocess.CalledProcessError: Command '['head', '-n', '2366468', 'data/noise/white_16k.dat', '|', 'tail', '-2183988']' returned non-zero exit status 1. What am I doing wrong? 回答1: Try with this : import subprocess # cmd contains shell command cmd="your