1
下面是產卵和Linux上的終端程序(可能還有其他的Unix)通信的位C樣板如何實現Windows的終端模擬器?
int master, slave;
struct winsize wsize = {24, 80, 0, 0}; // 24 rows and 80 columns
if (openpty(&master, &slave, NULL, NULL, &wsize) < 0)
die("Failed to open the pty master/slave");
if (!fork()) {
// child, set session id and copy the pty slave to std{in,out,err}
setsid();
dup2(slave, STDIN_FILENO);
dup2(slave, STDOUT_FILENO);
dup2(slave, STDERR_FILENO);
close(master);
close(slave);
// then use one of the exec* variants to start executing the terminal program
}
// parent, close the pty slave
close(slave);
// At this point, we can read/write data from/to the master fd, and to the child
// process it would be the same as a user was interacting with the program
我明白,窗戶沒有fork()
或openpty()
,所以我的問題是:如何實現在Windows上類似的東西?
如果可能的話,我想看看做以下所需的工作C/C++代碼的最低金額:使用CreateProcess
- 菌種的cmd.exe的交互式會話處理/文件描述符,可以用來從模擬交互式控制檯會話的方式讀取/寫入衍生進程的數據。
我還沒有找到。我不明白,這個問題是如何與線程相關的? –
'fork'的功能是什麼?你可以使用線程而不是進程? –
不,叉有創建一個新的過程,然後運行終端程序 –