How to supply a command to 'stdin' of a running process from a second shell?
1
vote
2
answers
3728
views
If you have a process that is waiting for user-input from the
stdin
scope, then how can you supply that user-input from a second terminal ?
Specifically, if I run the c-program
while(1){
fgets(string, len, stdin);
string[strlen(string)-1] = 0;
if(strcmp("Stop", string) == 0){
printf("Gotcha");
return 1;
}
}
then how can I supply the string "Stop" to stdin
of that process from another process, such that the first process will stop (and print "Gotcha") ?
I've tried to run the c-program in terminal 'pts/0' and open a new terminal ('pts/1') with commands:
$ echo "Stop" > /proc//fd/0
$ echo "Stop" > /dev/pts/0
where pid is the process id. The "Stop"-command is "repeated" in the first shell, but the process does not receive it.
Asked by drC1Ron
(181 rep)
Dec 21, 2018, 03:05 PM
Last activity: May 19, 2025, 01:05 AM
Last activity: May 19, 2025, 01:05 AM