我有两个独立的过程:一个C程序,它输出逗号分隔值,后面每秒一个换行符,一个Perl程序接受数据(格式相同)并处理这些数据.
C程序输出(通过printf)值如下:
1, 2, 3, 4, 5, 6
7, 8, 9, 10, 11, 12
...
Run Code Online (Sandbox Code Playgroud)
Perl程序位于一个无限循环中,等待STDIN的行,以便处理这些数据:
while ($line = <STDIN>)
{
chomp($line) # Line should now read "1,2,3,4,5,6"
# Process data
}
Run Code Online (Sandbox Code Playgroud)
我希望这两个过程实时通信.标准bash管道不起作用(例如process1 | process2),因为Perl程序在处理输入之前等待第一个程序完成.
有没有人对这个问题的解决方案有任何想法,建议或见解?先感谢您!