问题
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