问题描述
我使用以下方法制作了伪终端: http://lists.apple.com/archives/student-dev/2005/Mar/msg00019.html
I made a pseudo terminal with method described here: http://lists.apple.com/archives/student-dev/2005/Mar/msg00019.html
终端本身运行良好.无论如何,问题是无法将终端切换到子进程.例如,我用NSTask
启动了bash
,如果我在bash
中执行ftp
,它将自动停止.
The terminal itself worked well. Anyway the problem is terminal cannot being switched to child process. For an example, I launched bash
with NSTask
, and if I execute ftp
within the bash
, it stops automatically.
ftp
ftp
ftp>
[1]+ Stopped ftp
bash-3.2$
如果我尝试将ftp
继续使用fg
,它将安静地终止. (我通过活动监视器进行了检查)
And if I try to continue the ftp
with fg
, it terminates quietly. (I checked this with Activity Monitor)
fg
fg
ftp
bash-3.2$
fg
fg
bash: fg: current: no such job
bash-3.2$
我认为它需要更多基础结构(完成伪终端)才能将控制切换到子进程.要做什么?
I think it needs some more infrastructure (which completes pseudo terminal) to switch control to child process. What's required to do this?
推荐答案
我终于可以通过创建pty
设备来做到这一点.为了使程序的行为像终端"一样,它必须在交互式终端中执行,并且需要伪终端设备.
I could finally do this by creating a pty
device. To make a program behave like "Terminal", it must be executed in an interactive terminal, and that needs pseudo-terminal device.
不幸的是,AFAIK NSTask
不支持任何pty
功能,因此我不得不深入到BSD层.
Unfortunately, AFAIK, NSTask
does not support any pty
ability, so I had to get down to BSD layer.
这是我当前的实现: https://github.com/eonil/PseudoTeletypewriter.Swift
sudo
运行良好,我相信ssh
也应该运行.
sudo
is working well, and I believe ssh
should also work.
这篇关于如何将终端切换到使用NSTask启动的新进程子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!