从 C++ exe 中获取输出并在 Python 中实时处理它

Take output from C++ exe and work on it in Python in real time

我有一个 C++ 可执行文件,用于眼动仪,printf 的注视坐标指向终端。我需要能够将这些放入 Python 以进行数据分析等。如果有一种方法可以实时执行此操作,那就太棒了,这样我就可以在 python 中处理传入的数据.我发现最有用的东西是:http://fluxtrap.blogspot.co.uk/2011/09/dead-simple-real-time-plotting-with-cc.html。然而,这似乎是针对 UNIX 的,我在 Windows 上。所以我的问题是,是否有类似的技术可以让我 运行 我的 c++ 程序并在 Python 中使用它的数据?

However this seems to be for UNIX, and I'm on Windows. So my question is, is there a similar technique such that I can run my c++ program and use it's data in Python??

如前所述,here windows cmd.exe shell(以及 powershell 也)以相同的方式支持 | 符号,正如 linux/unix shell 所做的那样。

有一点特别(对于两种 OS)是您需要显式调用 python 解释器。所以 运行 你的东西像

mycppprogram | python mypyscript.py

应该努力实现你想要的。