First of all, I don't know how to search what I want to do.
I have one exec that produces outputs in a terminal (Linux). Let's take a simple C program a.out:
#include <stdio.h>
int main (int argc, char *argv[]) {
int i=0;
float j=0;
for(i=0; i<=10000000;i++)
{
j = i*-1e-5;
printf (" %d 2.0 %f 4.0 5.0\n",i,j);
}
}
Outputs produced are like :
0 2.0 -0.000000 4.0 5.0
1 2.0 -0.000010 4.0 5.0
2 2.0 -0.000020 4.0 5.0
3 2.0 -0.000030 4.0 5.0
...
Depending on this outputs I want to :
- Launch this exec
- "Capture" outputs
- If 3rd column value reach -0.5, stop/kill exec
How will you do this ?
For instance, exec is not stopped with this script exec.sh:
#/bin/sh
PROG=./a.out
$PROG > output &
progpid=$!
(tail -fn 0 output & echo $! > tailpid ) | awk -v progpid=$progpid '{
if($3<=-0.5){
system("kill "progpid)
# system( ##update other file )
system("kill $(<tailpid)")
}
}'
Any ideas ?
Thanks in advance