简体   繁体   中英

Executing Linux command in Python with special characters

I just want to execute the command rm /tmp/*.idx from a python script. I have read that os.system is deprecated (IT IS NOT, see the comments), so I'm trying with Popen the following:

proc = subprocess.Popen(shlex.split('rm /tmp/*.idx'))
proc.communicate()

after of course importing shlex and subprocess , but it doesn't erase the files.

Thanks.

Glob patterns are shell syntax. So:

subprocess.Popen("rm /tmp/*.idx", shell=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM