I was wondering how one might connect to a screen process in C/C++, I often want to have a C program listen to the output to that screen window and react to that output as well as send some input to the program running on that session. I am just unsure as to how I'm supposed to connect to that screen session and I haven't found anything very useful doing my searches.
我想知道如何在C/ c++中连接到一个屏幕进程,我经常想要一个C程序监听输出到那个屏幕窗口,并对那个输出做出反应,并向运行在该会话上的程序发送一些输入。我只是不确定我应该如何连接到那个屏幕会话,我还没有发现在我的搜索中有什么非常有用的东西。
1 个解决方案
#1
1
Doing exactly what you want is involved. screen expects to be running inside a terminal device, so if (I'm assuming you are on linux) you want to create it programatically you have to set up a terminal pseudodevice using posix_openpt()
, set up the slave device with grantpt()/unlockpt()
, forking, opening the slave pty in the child process, duping it to stdin/out/err, and finally exec'ing screen with the appropriate options. Now you can send commmands and receive terminal notifications as if you were a terminal emulator. Check the man page for pty(7)
for more details; I'm quite sure I've missed some.
要做你想做的事。屏幕将是运行在一个终端设备,如果(我假设你是在linux上)你想创建它编程上你必须建立一个终端使用posix_openpt pseudodevice(),建立了奴隶设备grantpt()/ unlockpt(),分叉,打开奴隶企业子进程,欺骗stdin / /犯错,最后exec操作屏幕与适当的选项。现在,您可以发送commmands并接收终端通知,就像您是终端模拟器一样。详细信息请查看手册页pty(7);我肯定我漏掉了一些。
Which is all a huge mess, and almost certainly overcomplicated for what you are trying to do. So: what are you actually trying to do?
这是一个巨大的混乱,而且几乎可以肯定的是你想要做的事情过于复杂。那么:你到底想做什么?
#1
1
Doing exactly what you want is involved. screen expects to be running inside a terminal device, so if (I'm assuming you are on linux) you want to create it programatically you have to set up a terminal pseudodevice using posix_openpt()
, set up the slave device with grantpt()/unlockpt()
, forking, opening the slave pty in the child process, duping it to stdin/out/err, and finally exec'ing screen with the appropriate options. Now you can send commmands and receive terminal notifications as if you were a terminal emulator. Check the man page for pty(7)
for more details; I'm quite sure I've missed some.
要做你想做的事。屏幕将是运行在一个终端设备,如果(我假设你是在linux上)你想创建它编程上你必须建立一个终端使用posix_openpt pseudodevice(),建立了奴隶设备grantpt()/ unlockpt(),分叉,打开奴隶企业子进程,欺骗stdin / /犯错,最后exec操作屏幕与适当的选项。现在,您可以发送commmands并接收终端通知,就像您是终端模拟器一样。详细信息请查看手册页pty(7);我肯定我漏掉了一些。
Which is all a huge mess, and almost certainly overcomplicated for what you are trying to do. So: what are you actually trying to do?
这是一个巨大的混乱,而且几乎可以肯定的是你想要做的事情过于复杂。那么:你到底想做什么?