Reputation: 16837
I have a situation where there is a running terminal process. I can find the PID of the terminal. I want to inject a command s.t. it runs and prints output in the target terminal process. I tried the following:
# Assuming terminal with PID is running in a different window
$ echo "ls\n" > /proc/PID/fd/0
This just prints the string in the second terminal window. How can I send a command (like ls) and then an enter key press into the second terminal window ? Thanks
Upvotes: 0
Views: 304
Reputation: 26557
If you have xdotool
installed ;
$ xdotool search --pid 2981 # 2981 being the PID of terminal, not shell
60817444
$ xdotool windowfocus --sync 60817444 type $'ls\n'
Upvotes: 1