windows保存输出到文件的命令行程序, 能不能直接输出到python内存?

如题, 假设有一个命令行程序a.exe, 可以指定输入输出文件, 如
a.exe input.txt -o output.txt
在python中调用, 能不能直接输出到python中定义的一个字符串?

用subprocess的popen,以前写的gdb的输出的例子copy过来给你参考。
import subprocess

gdbexe = "linux-gdb\powerpc-elf-linux-gdb.exe"
    gdbinput = corefilename
    proc = subprocess.Popen(gdbinput, stdin=subprocess.PIPE,  stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    while proc.poll() == None:
        self.ResultCtrl.AppendText('.')
        txt = proc.stdout.readline()

可以使用os.popen,具体调用如下:
import os

fd = os.open('a.exe')
str = fd.read()
fd.close()

这样str的内容就是a.exe输出的字符串了

应该可以,电脑从来没有出现过这样的问题。