Python标准不打印或保存

2024-04-27 04:27:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将子进程中的文本消息保存在一个变量中,但它们没有保存,也不再打印。有人能解释我为什么困惑吗:

import os
import subprocess
import sys
import re

locationOfFile='C:\\Users\\admin\\Desktop\\..........txt'

command="cmd"
subprocess.Popen(command)

process="mycommand"

command3=subprocess.Popen(process, stdout=subprocess.PIPE)

#Usially with this command in the child process I  receave many messages, but with stdout I dont see them. I dont want to hide them from the console, just to go in that variable as a string "resultt"
resultt=command3.communicate()

print(resultt)
#But it is not printing?

Tags: thetoinimportwithstdoutprocesscommand