2024-04-26 07:07:28 发布
网友
这样做最好的是什么?你知道吗
正如@Keith建议使用subprocess模块,但更具体地说是使用Popen。例如,在Windows上,这将打开myfile.txt文件然后在20秒后终止:
import subprocess import time command = "notepad myfile.txt" pipe = subprocess.Popen(command, shell=False) time.sleep(5) pipe.poll() print("%s" % pipe.returncode) #"None" when working fine time.sleep(5) pipe.terminate() pipe.wait() print("%s" % pipe.returncode) # 1 after termination
正如@Keith建议使用subprocess模块,但更具体地说是使用Popen。例如,在Windows上,这将打开myfile.txt文件然后在20秒后终止:
相关问题 更多 >
编程相关推荐