0

I have two bash processes running. Let's name them bash_1 and bash_2. I wish to execute command in bash_1 from bash_2. I am following this method to achieve this.

Get the dev file for IO in bash_1

vchandola@mininet-server:~$ echo $$  
1097
vchandola@mininet-server:~$ ls -alh /proc/1097/fd  
total 0  
dr-x------ 2 vchandola vchandola  0 Jul 11 15:48 .  
dr-xr-xr-x 9 vchandola vchandola  0 Jul 11 15:48 ..  
lrwx------ 1 vchandola vchandola 64 Jul 11 15:48 0 -> /dev/pts/2  
lrwx------ 1 vchandola vchandola 64 Jul 11 15:48 1 -> /dev/pts/2  
lrwx------ 1 vchandola vchandola 64 Jul 11 15:48 2 -> /dev/pts/2  
lrwx------ 1 vchandola vchandola 64 Jul 11 16:08 255 -> /dev/pts/2  

Execute following in bash_2 to execute commands in bash_2 to execute bash commands in bash_1

root@mininet-server:/home/vchandola# socat - /dev/pts/2
hello
ls

I was expecting responses of these in bash_2 but don't see them. In bash_1 both the strings have came but looks like Enter/newline character is not read/served as expected. This is what I see in bash_1

vchandola@mininet-server:~$ hello
ls

Why hello and ls commands were not executed in bash_1? What can I do to execute hello and ls in bash_1?

1 Answer 1

1

If you have two shells, shell-1 and shell-2:

(shell-1) $ who am i
user     pts/0        ...

(shell-2) $ who am i
user     pts/1        ...

Then writing to the associated character device will result in that output getting printed to the associated terminal (as you've seen):

(shell-2) $ echo hello > /dev/pts/0
$

(shell-1) $ hello

Writing to that device from shell-2 is in no way different that writing to it from shell-1. If you do a echo hello on shell-1, that also writes to /dev/pts/0, and that doesn't become input to that shell, it's written to the terminal's "screen".

If you want a process to write a shell's standard input stream, you'd need to use a different mechanism (e.g., a pipe or fifo), and that would need to be set up by the process that exec'ed the shell.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .