使用Python代码连续读取背景C程序的控制台输出

发布于 2025-02-08 15:15:36 字数 219 浏览 4 评论 0原文

我在Linux系统上,我的交流代码正在从连续计算中输出数据, 我想在背景中运行此代码,并从Python代码中解析此数据。 Python代码将是前景中的代码。 我在想这样的事情:(

>mycode  &
>python3 mypythoncode

“>”是Linux提示) 但是这种方法很好吗? Python代码相同的相应代码是什么?

I am on linux system ,I have a c code which is outputting data from a continuous calculation,
I want to run this code in background and parse this data from a python code. Python code will be the one in the foreground.
I was thinking something like this :

>mycode  &
>python3 mypythoncode

(">" is the linux prompt)
but is this approach fine? what will be the corresponding code for the same for python code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是暖光i 2025-02-15 15:15:36

好的,我弄清楚了:

我的C代码:

#include <stdio.h>
int main()
{
  while(1)
          printf("hello World from c \n");
         return 0;
}

我的Python代码

import fileinput

for line in fileinput.input():
    print("from Python",line)
    pass

输出:

command :  ./p | python t.py



from Python hello World from c

from Python hello World from c

from Python hello World from c

OK i figured it out :

My c code :

#include <stdio.h>
int main()
{
  while(1)
          printf("hello World from c \n");
         return 0;
}

My Python code

import fileinput

for line in fileinput.input():
    print("from Python",line)
    pass

Output :

command :  ./p | python t.py



from Python hello World from c

from Python hello World from c

from Python hello World from c
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文