The command
$ find ~/foo/ -type f -iname "*.txt" -print0 | parallel -0 cat
uses GNU Parallel to print all the .txt
files under ~/foo/
.
I have a python script where I want to call this bash command:
import subprocess, sys
def runBashCommand(my_command):
process = subprocess.Popen(my_command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
return None
def makeCommand(my_path):
return "find {} -type f -iname \"*.txt\" -print0 | parallel -0 cat".format(my_path)
Issuing
>>> makeCommand('~/foo/')
returns
'find ~/foo/ -type f -iname "*.txt" -print0 | parallel -0 cat'
but issuing
>>> runBashCommand(makeCommand('~/foo/'))
yields the error
find: paths must precede expression: |
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
what's the problem with my script?