子進程。打開嘗試寫入不存在的管道 [英] subprocess.Popen tries to write to nonexistent pipe

查看:0
本文介紹了子進程。打開嘗試寫入不存在的管道的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

為什么以下選項不起作用?

import subprocess

process = subprocess.Popen('cmd.exe', shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None)


我得到的輸出如下:

The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.

之后,該進程終止,不會出現錯誤。我正在運行Windows 7。

推薦答案

嘗試:

import subprocess
subprocess.run(["echo", "Hello, world!"], shell=True)

這使用默認的stdout和stderr,而不是創建管道。

這篇關于子進程。打開嘗試寫入不存在的管道的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持IT屋!

查看全文
登錄 關閉
掃碼關注1秒登錄
發送“驗證碼”獲取 | 15天全站免登陸
全免费A级毛片免费看无码播放