[英]Using rm * (wildcard) in envoy: No such file or directory
I'm using Python and Envoy. 我正在使用Python和Envoy。 I need to delete all files in a directory.
我需要删除目录中的所有文件。 Apart from some files, the directory is empty.
除了一些文件,目录为空。 In a terminal this would be:
在终端中,这将是:
rm /tmp/my_silly_directory/*
Common sense dictates that in envoy, this translates into: 常识要求在使节中,这转化为:
r = envoy.run('rm /tmp/my_silly_directory/*')
However: 然而:
r.std_err -> "rm: cannot remove `/tmp/my_silly_directory/*': No such file or directory"
Naturally there are alternatives to using envoy in this case, I am simply wondering why it doesn't work. 当然,在这种情况下有使用特使的替代方案,我只是想知道为什么它不起作用。
Any clues? 有线索吗?
On UNIX, it's up to the shell to interpret wildcards like *
. 在UNIX上,由shell来解释像
*
这样的通配符。 If you execute a program and pass an argument with *
in it directly to the program -- which is presumably what's being done here -- then you'll get an error like you're seeing. 如果你执行一个程序并将带有
*
的参数直接传递给程序 - 这可能就是在这里做的 - 那么你会得到一个像你所看到的错误。 rm
just assumes the *
is a file name, and indeed, it's actually possible to create such a file. rm
只是假设*
是文件名,实际上,实际上可以创建这样的文件。
One solution could be to execute the shell and let it execute your command on your behalf, something like 一种解决方案可能是执行shell并让它代表您执行命令,例如
r = envoy.run('sh -c "rm /tmp/my_silly_directory/*"')
The shell will interpret the *
before invoking rm
. shell将在调用
rm
之前解释*
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.