I am using the subprocess module to run a find & grep command with two different variables. I have a syntax error but I just don’t see it.
With one variable, it runs just fine:
path = "src"
path_f = "TC"
subprocess.Popen('find /dir1/tag/common/dir2/dir3 /dir1/tag/common/dir2/dir3/dir4/ -iname "%s"'%path, shell=True)
Two variables:
subprocess.Popen('find /dir1/tag/common/dir2/dir3 /dir1/tag/common/dir2/dir3/dir4/ -iname "%s"* | grep "%s" > fileList.txt'%path, %path_f, shell=True)
Can someone help ?
Thanks.
yakxxx is right, but
shell=Trueis not optimal.Better do
as it gives you better control over what happens, expecially no shell escaping crosses your way.
For example, imagine a
pathorpath_fvalue of'My 9" collection'etc. This will confuse the shell at both thefindand thegrepcommands. There are ways around it, but they are harder than the above.See here.