奇怪的子进程行为

时间:2017-07-18 10:33:03

标签: python subprocess

subprocess.call(["find", ".", "-exec", "sh", "-c", "echo testFirst", ";"])
subprocess.call(["find", ".", "-exec", "sh", "-c", "echo testSecond", ";"], shell=True)
subprocess.call(["find . -exec sh -c 'echo testThird' \\;"], shell=True)

subprocess.call(["find", ".", "-exec", "sh", "-c", "touch testFirst", ";"])
subprocess.call(["find", ".", "-exec", "sh", "-c", "touch testSecond", ";"], shell=True)
subprocess.call(["find . -exec sh -c 'touch testThird' \\;"], shell=True)

以下输出:

testFirst
testFirst
testFirst
.
./test.py
./data
testThird
testThird
testThird
.
./test.py
./testFirst
./data

仅创建testFirsttestThird个文件。

该行为的解释是什么?

我会假设testFirsttestSecondtestThird的输出以及正在创建的三个文件。

1 个答案:

答案 0 :(得分:0)

https://stackoverflow.com/a/10661488/1663462

  

当你传递shell = True时,Popen期望一个字符串参数,而不是   一个清单。

...........