当前位置:主页 > 软件编程 > Python代码 >

python隐藏终端执行cmd命令的方法

时间:2021-04-19 08:07:39 | 栏目:Python代码 | 点击:

在用pyinstaller打包后不想要后面的终端命令框,但是打包时加了-w或者--noconsole命令后会导致cmd程序不能运行从而出错。这个时候用subprocess可以解决该类问题。

import subprocess
 
cmd = 'your command'
res = subprocess.call(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

这样打包后出来的程序就不会出现命令框,而且也能够正常运行了。

您可能感兴趣的文章:

相关文章