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)

The following outputs:

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

And only testFirst and testThird files are created.

What is the explanation of the behaviour?

I would assume output of testFirst, testSecond, testThird as well as the three files being created.

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286

1 Answers1

0

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

When you pass shell=True, Popen expects a single string argument, not a list.

...........

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286