Tag: wxpython

Python逐行从子进程捕获stdout

我已经阅读了很多与此相关的问题并且学到了很多,但我仍然无法解决我的问题。 我正在构建一个运行c ++可执行文件的wxPython应用程序,并实时显示该可执行文件中的stdout。 我试图让这项工作遇到几个奇怪的结果。 这是我目前的设置/问题: //test.cc (compiled as test.out with gcc 4.5.2) #include int main() { FILE* fh = fopen(“output.txt”, “w”); for (int i = 0; i < 10000; i++) { printf("Outputting: %d\n", i); fprintf(fh, "Outputting: %d\n", i); } fclose(fh); return 0; } #wxPythonScript.py (running on 2.7 interpreter) def run(self): self.externalBinary = subprocess.Popen(['./test.out'], shell=False, stdout=subprocess.PIPE) […]