PyQt5界面上调用subprocess.Popen会闪命令窗口的问题

最近再作一个界面开发,主要实现的点击一个按钮,会执行adb安装应用程序的功能,在调试阶段一切都正常,但打包成一个exe安装程序,安装以后运行,点击按钮会闪一下adb的命令窗口shell

先列出subprocess.Popen方法介绍,里面有不少关键字参数app

1、subprocess.Popen
subprocess模块定义了一个类: Popen
class subprocess.Popen( args,
bufsize=0,
executable=None,
stdin=None,
stdout=None,
stderr=None,
preexec_fn=None,
close_fds=False,
shell=False,
cwd=None,
env=None,
universal_newlines=False,
startupinfo=None,
creationflags=0)spa

 

 

划重点:debug

cmd_test = "adb install xxx.apk"调试

subprocess.Popen(cmd_test, shell=True)
这是由于它至关于
subprocess.Popen(["cmd.exe", "-c", cmd_test])
在*nix下,当shell=False(默认)时,Popen使用os.execvp()来执行子程序code

因此若是不设置shell这个参数时,会默认会启动系统的命令窗口来显示操做,要不让它使用系统的,就将shell=True便可,就不会闪一下命令窗口的问题了。orm

将代码从新修改一下再次打包运行,果真就不会闪命令窗口界面了blog

 1     def install_app(self, file):
 2         try:
 3             install_cmd = r"adb install -g -t -r {}".format(file)
 4             log.debug("The install command is: {}".format(install_cmd))
 5             result_output = subprocess.Popen(install_cmd, stdout=subprocess.PIPE, shell=True)
 6             result_lst = result_output.stdout.readlines()
 7             for item in result_lst:
 8                 item_strip = item.decode("gbk").strip()
 9                 log.debug(item_strip)
10                 if "Success" == item_strip:
11                     return True
12             else:
13                 return False
14 
15         except Exception as e:
16             log.debug(e)
相关文章
相关标签/搜索