これは、Linux(およびおそらく他のUNIX)で端末プログラムを生成して通信するためのCボイラープレートのビットです。
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()
Windowsにはまたはがないことを理解していますopenpty()
ので、私の質問は次のとおりです。Windowsで同様のことを実現するにはどうすればよいですか?
可能であれば、次のことを実行するために必要な最低限の C/C++ コードを確認したいと思います。
- を使用して cmd.exe の対話型セッションを生成します
CreateProcess
- インタラクティブなコンソール セッションをシミュレートする方法で、生成されたプロセスとの間でデータを読み書きするために使用できる一連のハンドル/ファイル記述子を取得します。