Issue
for example, there is a C program test.c:
#include<stdio.h>
int main(){
int aa;
scanf("%d",&aa);
return 0;
}
I want to write a bash script that can automatically execute this program. And what's more, if the input in the C program (aa) needs to be delayed for a few seconds after the program is called, how should the script be written?
The problem is that I don't know how to set the delay.
./test<<EOF
8
<<EOF
Solution
If I understand correctly, you want to start the program with nothing in its input stream, and then a couple of seconds later provide some input? If that's right, you can pipe its input from what's essentially a small script that delays a couple of seconds, then sends data. Something like this:
{ sleep 2; echo "8"; } | ./test
Answered By - Gordon Davisson Answer Checked By - Gilberto Lyons (WPSolving Admin)