stderr=subprocess.PIPE改成stderr=subprocess.STDOUT,则错误输出和正常输出一样
def start(self):
exepath = "d:/test.exe"
command = "--file abc.txt"
args = exepath + " " + command
p = subprocess.Popen(args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
p.stdin.write('version\n') #需要加上\n
p.stdin.flush() #write完后,需要flush
while True:
line = p.stdout.readline()
if line != "":
print(line)
#持续交互
p.stdin.write('version\n') #需要加上\n
p.stdin.flush() #write完后,需要flush