开发者

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

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜