私はいくつかの選択肢を試しましたが、どれも満足できませんでした。私が見つけた最高のものはPopen
に切り替わりました。
# this should have the a similar signature to check_call
def run_in_shell(*args):
# unfortunately, `args` won't be escaped as it is actually a string argument to bash.
proc = subprocess.Popen(['/bin/bash', '-c', ' '.join(args)])
# This will also work, though I have found users who had problems with it.
# proc = subprocess.Popen(' '.join(args), shell=True, executable='/bin/bash')
stat = proc.wait()
if stat != 0:
subprocess.CalledProcessError(returncode=stat, cmd=command)
return stat
run_in_shell("cat parsing.tgz <(echo -n ''| gzip)> new-file.tgz")
注:/bin/sh
は、エスケープされていない括弧に問題があります。あなたは上記の'/bin/bash'
を指定したくない場合は、括弧をエスケープする必要があります。
args = 'cat parsing.tgz <\\(echo -n ''| gzip\\)> new-file.tgz'
「機能しません」とはどういう意味ですか? – Chris
@Chris;あなたのコメントに固有の質問を更新しました。 – Viswesn
トピックを削除しますが、 'split()'の代わりに['shlex.split()'](https://docs.python.org/3.5/library/shlex.html#shlex.split)を使用してください。 – squiguy