我试图使用子进程模块(python)执行以下命令。文件路径> -maxdepth 1 -type f -iname< pattern> -exec basename {} \;
但是,它给出了以下错误: < pre $ / usr / bin / find:缺少参数到`-exec'
我猜这是为了逃避某些角色。但没有得到如何克服这一点。
任何帮助表示赞赏。谢谢。
解决方案另一个问题的答案帮助: stackoverflow/a/15035344/971529
import subprocess subprocess.Popen(('find','/ tmp / mount','-type','f','-name','* .rpmsave',' -exec','rm','-f','{}',';'))我无法弄清楚的是,分号不需要转义,因为通常分号是由bash解释的,需要被转义。
在bash中,这个等价物是: $ b $ pre $ find $ / tmp / mount -type f -name* .rpmsave -exec rm -f {} \;
I'm trying to execute the following command using subprocess module (python)
/usr/bin/find <filepath> -maxdepth 1 -type f -iname "<pattern>" -exec basename {} \;But, it gives the following error :
/usr/bin/find: missing argument to `-exec'I am guessing it's to do with escaping some characters. But not getting how to get over this.
Any help is appreciated. Thanks.
解决方案An answer on another question helped: stackoverflow/a/15035344/971529
import subprocess subprocess.Popen(('find', '/tmp/mount', '-type', 'f', '-name', '*.rpmsave', '-exec', 'rm', '-f', '{}', ';'))The thing I couldn't figure out was that the semi-colon didn't need to be escaped, since normally the semi-colon is interpreted by bash, and needs to be escaped.
In bash this equivelent is:
find /tmp/mount -type f -name "*.rpmsave" -exec rm -f {} \;
更多推荐
在python子进程中用exec找到命令给出错误
发布评论