【问题标题】:Python Subprocess causing latency with shell [duplicate]Python子进程导致shell延迟[重复]
【发布时间】:2014-06-30 13:53:39
【问题描述】:

下面的代码完全可以正常工作。但是,一旦调用子进程并执行外部 python 脚本,它就会开始快速弹出命令提示符,因为脚本的输出是纯文本。但是,我们已尽一切努力禁用该弹出窗口。我们尝试添加“shell=False”和“shell=None”。我们甚至尝试编辑外部脚本本身并修改其子进程调用,但它没有。

if os.path.exists(oldpath): shutil.copy(root.wgetdir + "\\" + root.website.get() + "\\" + item, keyworddir + "\\" + item)
            shellreturn = subprocess.check_output(["C:\Python34\python",root.wgetdir + "\html2text.py", keyworddir + "\\" + item])
            print(shellreturn)
            shelllist = shellreturn.decode().splitlines()

【问题讨论】:

    标签: python shell subprocess latency


    【解决方案1】:

    感谢@J.F. 的相关帖子。塞巴斯蒂安,我能够弄清楚如何消除外壳弹出窗口。下面是我使用的代码。

    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW      
    shellreturn = subprocess.check_output(["C:\Python34\python", root.wgetdir + "\html2text.py", keyworddir + "\\" + item], startupinfo=startupinfo) #this could be any subprocess.
    

    【讨论】:

    • 使用r"C:\Python\n\f" 而不是"C:\Python\n\f"。后者有文字换行符("\n")。使用os.path.join(keyworddir, item) 而不是keyworddir + "\\" + item
    猜你喜欢
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2020-04-29
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多