您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在没有控制台的情况下使用Popen在pythonw中运行进程

在没有控制台的情况下使用Popen在pythonw中运行进程

这里

import subprocess

def launchWithoutConsole(command, args):
    """Launches 'command' windowless and waits until finished"""
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    return subprocess.Popen([command] + args, startupinfo=startupinfo).wait()

if __name__ == "__main__":
    # test with "pythonw.exe"
    launchWithoutConsole("d:\\bin\\gzip.exe", ["-d", "myfile.gz"])

请注意,有时抑制控制台会使子流程调用失败,并显示错误6:无效的句柄”。一种快速修复是重定向stdin,如此处所述:以Windows服务运行的Python:OSError:[WinError 6]句柄无效

python 2022/1/1 18:35:16 有601人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶