How to switch terminal to new child process of process launched with NSTask?

☆樱花仙子☆ 提交于 2019-12-23 03:37:32

问题


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?


回答1:


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 any pty 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 believe ssh should also work.




回答2:


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.



来源:https://stackoverflow.com/questions/7545133/how-to-switch-terminal-to-new-child-process-of-process-launched-with-nstask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!