[英]Executing Linux command in Python with special characters
I just want to execute the command rm /tmp/*.idx
from a python script. 我只想从python脚本执行命令rm /tmp/*.idx
。 I have read that os.system
is deprecated (IT IS NOT, see the comments), so I'm trying with Popen the following: 我已经阅读os.system
不推荐使用os.system
(它不是,请参见注释),所以我尝试使用Popen进行以下操作:
proc = subprocess.Popen(shlex.split('rm /tmp/*.idx'))
proc.communicate()
after of course importing shlex
and subprocess
, but it doesn't erase the files. 之后当然进口shlex
和subprocess
,但它不会删除文件。
Thanks. 谢谢。
Glob patterns are shell syntax. 球形模式是shell语法。 So: 所以:
subprocess.Popen("rm /tmp/*.idx", shell=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.