感謝Mark Plotnick,他在評論中回答如下。使用ioctl你可以寫入自己的tty。 C程序:
#include "unistd.h"
#include "stdlib.h"
#include "stdio.h"
#include "sys/stat.h"
#include "sys/types.h"
#include "fcntl.h"
#include "termios.h"
#include "sys/ioctl.h"
int main(int argc, char ** argv)
{
if (argc >= 3)
{
int fd = open (argv[1], O_RDWR);
if (fd)
{
char * cmd = argv[2];
while(*cmd)
ioctl(fd, TIOCSTI, cmd++);
if (argc >= 4)
ioctl(fd, TIOCSTI, "\r");
return 0;
}
else
printf("could'n open file\n");
}
else
printf("wrong args\n");
return -1;
}
編譯: 的gcc -o my_ioctl.c my_ioctl
.profile文件的盡頭:
~/my_ioctl $(tty) emacs rr
(我的C程序不關心什麼第三個參數的實際是)。
我不能幫你解決你的問題。但你不應該那樣做。混淆登錄過程的結果(例如使用ksh而不是bash或類似的東西)會導致問題。我學了幾次。 :-)但是有人在shell上默認使用emacs讓我回到人類的信心 – mbieren
感謝您的回答。你應該看到我用它的設備(我稱之爲「pocket emacs」和「pocket debugger」)。它的索尼Vaio VGN-P31ZRK。大多數「特殊按鈕」用於綁定) https://pp.userapi.com/c626117/v626117672/31b16/slek7sMxMbk.jpg –
相關:[詢問一個正在運行的bash(交互式)從外部運行命令](https://stackoverflow.com/questions/7370538/ask-a-running-bash-interactive-to-run-a-command-from-outside)和[無法使用termios.TIOCSTI僞造終端輸入](https ://stackoverflow.com/questions/29614264/unable-to-fake-terminal-input-with-termios-tiocsti)。在'.profile'的最後,你可以有一個perl或者python或者c程序發送'emacs \ r'到你的tty,這將使你的shell運行它,就像你輸入它一樣。 –