2017-07-18 150 views
0
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

這不是我的實際代碼,我只是縮小範圍來證明問題。 –

回答