Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在linux shell脚本上检测输出流_Bash_Shell_Stream_Output - Fatal编程技术网

Bash 在linux shell脚本上检测输出流

Bash 在linux shell脚本上检测输出流,bash,shell,stream,output,Bash,Shell,Stream,Output,我正在尝试在linux上编写一个shell脚本来检测输出蒸汽上的字符串 这是我的shell脚本 #!/bin/bash ./binary 二进制文件由源文件编译而成,如下所示: gcc-4.6 main.c -o binary //main.c #include "stdio.h" void main(){ int i; for (i=0; i<100; i++){ printf("data: %d\n", i); sleep(1); /

我正在尝试在linux上编写一个shell脚本来检测输出蒸汽上的字符串

这是我的shell脚本

#!/bin/bash
./binary
二进制文件由源文件编译而成,如下所示:

gcc-4.6 main.c -o binary 

//main.c
#include "stdio.h"
void main(){
    int i;
    for (i=0; i<100; i++){
       printf("data: %d\n", i);
       sleep(1);  // delay 1s
    }
}
gcc-4.6 main.c-o二进制文件
//main.c
#包括“stdio.h”
void main(){
int i;

对于(i=0;i当
stdout
未连接到终端时,默认情况下会对其进行完全缓冲。因此,如果您希望能够立即检测输出(如代码中
睡眠(1);
的建议),则需要在打印后刷新缓冲区

#include "stdio.h"
void main(){
    int i;
    for (i=0; i<100; i++){
        printf("data: %d\n", i);
        fflush(stdout);
        sleep(1);  // delay 1s
    }
}
#包括“stdio.h”
void main(){
int i;

对于(i=0;i当您检测到它时,您想做什么?可能像读取行时执行
/binary>一样简单;如果测试“$line”,则执行此操作='data:10';然后执行任意操作;fi;done
。一次或一行一行地执行所有输出?我觉得没问题。我可以在不等待命令完成的情况下写入文件。您能解释一下如何使用管道在shell scrip上执行输出吗?我想使用管道检查而不是写入文件