Ask a running bash (interactive) to run a command from outside

前端 未结 2 447
说谎
说谎 2020-12-10 00:13

I have a terminal (xterm) open with bash running in it, showing a prompt. Suppose I know this running bash\'s pid and the tty associated with this terminal. Is there any w

2条回答
  •  余生分开走
    2020-12-10 00:23

    Use a TIOCSTI ioctl. Example in C:

    char* cmd="ls\n";
    int fd = open (ptsname, O_RDWR);
    
    while (*cmd)
    {
        ioctl(fd, TIOCSTI, cmd++);
    }
    

提交回复
热议问题