我有一个 Python 脚本,与某些网络池进行接口以读取数据。这些数据不断变化,长度为 320 位。这 320 位应该被转发到某个 C 应用程序中,该应用程序不断地从 Python 脚本中读取这些 320 位并将它们放入一个 int 数组 [8] 中。说实话,我不知道这是否可能,并且会感谢您给出这个问题的一个起点。
我尝试了一些您的想法,尝试通过 stdin 从 Python 向 C 应用程序发送数据:
test.exe:
我尝试了一些您的想法,尝试通过 stdin 从 Python 向 C 应用程序发送数据:
test.exe:
#include <stdio.h>
int main(void)
{
int ch;
/* read character by character from stdin */
do {
ch = fgetc(stdin);
putchar(ch);
} while (ch != EOF);
return 0;
}
test.py:
def run(self):
while True:
payload = 'some data'
sys.stdout.write(payload)
time.sleep(5)
然后我使用管道启动整个过程:python test.py | test.exe
不幸的是,在test.exe端没有接收到任何数据,这些数据应该在stdin上可用吗?
sys.stdout.flush()
。 - jfs