I found out how to automatically send input to a C program using Shell Script. For example, if I compile this C program:
//test.c int main() } int x; printf("Please enter an integer:"); scanf("%d", &x); printf("\nYou entered %d\n", x); }
and write this script:
#!/bin/bash ./test << EOF 5 EOF
and open the terminal and run the script I will get this output:
Please enter an integer: You entered 5
Now, I want test to run on a new terminal, which I found out that I can do with this command: gnome-terminal -x ./test
The problem is, if I try to do both at the same time in my script (run test on a new terminal AND automatically send input), it doesn't work, the input doesn't get sent on the new terminal, you just have to give it yourself like you normally would.
What am I doing wrong and how to fix this?
P.S. Sorry if the format is a bit messed up, I tried.