linux - write commands from one terminal to another

前端 未结 7 1599
刺人心
刺人心 2020-12-29 09:54

I need to write commands from one terminal to another terminal.

I tried these:

echo -e \"ls\\n\" > /proc/pid/fd/0
echo -e \"ls\\n\" > /dev/pts/         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 10:06

    Python code:

    #!/usr/bin/python
    
    import sys,os,fcntl,termios
    if len(sys.argv) != 3:
       sys.stderr.write("usage: ttyexec.py tty command\n")
       sys.exit(1)
    fd = os.open("/dev/" + sys.argv[1], os.O_RDWR)
    cmd=sys.argv[2]
    for i in range(len(cmd)):
       fcntl.ioctl(fd, termios.TIOCSTI, cmd[i])
    fcntl.ioctl(fd, termios.TIOCSTI, '\n')
    os.close(fd)
    

提交回复
热议问题