如何将终端切换到使用 NSTask 启动的进程的新子进程?
我使用此处描述的方法制作了一个伪终端: http://lists .apple.com/archives/student-dev/2005/Mar/msg00019.html
终端本身运行良好。无论如何,问题是终端无法切换到子进程。例如,我使用 NSTask
启动了 bash
,如果我在 bash
中执行 ftp
,它会自动停止。
ftp
ftp
ftp>
[1]+ Stopped ftp
bash-3.2$
如果我尝试使用 fg
继续 ftp
,它会安静地终止。 (我用活动监视器检查了这一点)
fg
fg
ftp
bash-3.2$
fg
fg
bash: fg: current: no such job
bash-3.2$
我认为它需要更多的基础设施(完成伪终端)来将控制权切换到子进程。这样做需要什么?
I made a pseudo terminal with method described here: http://lists.apple.com/archives/student-dev/2005/Mar/msg00019.html
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$
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我终于可以通过创建一个 pty 设备来做到这一点。要使程序表现得像“终端”,它必须在交互式终端中执行,而这需要伪终端设备。
不幸的是,据我所知,
NSTask
不支持任何pty
功能,所以我不得不深入到 BSD 层。这是我当前的实现: https://github.com/eonil/PseudoTeletypewriter.Swift
sudo 工作良好,我相信 ssh 也应该工作。
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.Unfortunately, AFAIK,
NSTask
does not support anypty
ability, so I had to get down to BSD layer.Here's my current implementation: https://github.com/eonil/PseudoTeletypewriter.Swift
sudo
is working well, and I believessh
should also work.查看 MFTask 和 PseudoTTY.app 的源代码(适用于 Mac OS X 10.6)。
:http://www.cocoadev.com/index.pl?NSTask
请参阅 pty 命令行工具请参阅此处。
Have a look at the source code of MFTask and PseudoTTY.app (which works on Mac OS X 10.6).
See: http://www.cocoadev.com/index.pl?NSTask
For a pty command line tool see here.