【发布时间】:2018-08-14 12:09:38
【问题描述】:
import subprocess
name = raw_input("Enter the name of the file: ")
subprocess.Popen(["find", "-name", "*.spec", "|", "grep", name, "|", "xargs", "rm"], cwd="/opt/blusapphire/app/master/dist", stdout=subprocess.PIPE)
我已经在 python 文件中编写了上面的代码。我的目标是删除一个文件,即 abc.spec
所以当我执行时
python <filename>.py
它会询问文件名。当我给 abc 它应该只删除 abc.spec 文件
但上面的代码给出了以下错误
find: paths must precede expression: abc
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
【问题讨论】:
-
您的问题可以简化为
subprocess.Popen(["echo", "hello", "|", "cat"])。
标签: python find subprocess