如何将终端切换到使用NSTask启动的新进程子进程? [英] How to switch terminal to new child process of process launched with NSTask?

查看:147
本文介绍了如何将终端切换到使用NSTask启动的新进程子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下方法制作了伪终端: 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启动的新进程子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆