我用的是python 3和debian
我希望有一个使用os.system的函数。为了简单起见,大致是这样的:
def notxt():
command = "rm *.txt"
os.system(command)
notxt()
但是当我运行脚本时,它在没有执行命令的情况下挂起。有没有办法绕过这个问题,或者我是不是做错了?
发布于 2018-08-05 07:24:06
我会在这里使用子进程,然后使用run。像这样
import subprocess
subprocess.run(["rm", "1.txt"])
您可能需要另一个bash命令来删除所有txt文件
以下是文档:
https://stackoverflow.com/questions/51686287
复制相似问题