use*_*700 11 linux terminal redirect stdin tty
我需要将命令从一个终端写入另一个终端.
我试过这些:
echo -e "ls\n" > /proc/pid/fd/0
echo -e "ls\n" > /dev/pts/4
Run Code Online (Sandbox Code Playgroud)
它只打印ls
输出而不执行.
我试过这些:
chmod 777 /dev/tty4 ;echo "ls" > /dev/tty4
chmod 777 /dev/tty40 ;echo "ls" > /dev/tty40
Run Code Online (Sandbox Code Playgroud)
哪个似乎什么也没做
有任何想法吗?
[请注意,我不想触摸第二个终端来完成此任务.只有第一个]
Python代码:
#!/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)
Run Code Online (Sandbox Code Playgroud)
Chr*_*ton -1
这是错误的方法 - 您可能会在终端中显示它,但不会执行。
您需要执行一些操作,例如告诉 shell 从命名管道或 netcat/socat 读取数据。或者你可以尝试以root身份注入击键或使用xtest(有时在X下还有另一种方法,我忘记了)。
归档时间: |
|
查看次数: |
14271 次 |
最近记录: |