forkpty, but I've been unable to get it working from a swift executable.
forkptycall is not safe to use from Swift. It basically involves a fork without an exec, and it’s not safe to run Swift code in that environment (it’s the same for Objective-C).
I believe the issue is that I need to pass input to
amaster, which I'm unsure how to do:
Not quite (-: Before we start, a note on terminology. While the pseudo terminal documentation is full of references to master and slave, I’m not going to use those in any text I write. Instead I’m going to use the names of the terminal devices themselves, pty and tty respectively.
You want to pass tty to the child process, not pty. You want to retain pty and use it to control tty. See the
ptyman page for more background on this.
You need to pass tty to the child thrice, for
standardError. I don’t think you need to do anything special here;
FileHandlewill do the right thing if you assign it to all three properties.
Once the child is running, make sure you close your copy of tty. Otherwise things can get very confusing.
Finally, this stuff is deep UNIX arcana and, as such, is best documented in various UNIX texts. My go-to book for this sort of thing in Advanced Programming in the Unix Environment. Get it, read it!
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"