奇怪子行为

问题描述:

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文件被创建。

行为的解释是什么?

我会假设输出为testFirst,testSecond,testThird以及正在创建的三个文件。

+0

为什么你需要前4个参数呢? –

+0

这不是我的实际代码,我只是缩小范围来证明问题。 –

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

当你通过壳=真,POPEN期待一个字符串参数,而不是 列表。

...........