Sample Header Ad - 728x90

zsh zpty does not work on macOS, does work on Linux?

2 votes
1 answer
387 views
zsh module zsh/zpty seems to work perfectly well on my Linux virtual machine running on Apple M1 macOS machine. But the same does not work on macOS (even on the same host machine). I have tried this with both the build of zsh that comes preinstalled on macOS `/bin/zsh` and one that is installed from homebrew. In my observation, a process is indeed created when zpty command is executed to create pseudo terminal and run a command in it. But after that, writing to process does not work. Here's some example, I entered the following commands one by one in an interactive zsh session:
zmodload zsh/zpty
zpty -b hello 'vim --clean'
zpty -w hello ':e foo'
zpty -w hello $'aHello there from foo file\e:w'
cat foo
zpty -d hello
On macOS `cat would fail with cat: foo: No such file or directory. On Linux you will see Hello there from foo file`. What am I trying to achieve with zpty? I would like to start a process in a pseudo terminal as promised by the zsh manual, and send it input asynchronously. I don't care about the stdout of process. An ideal solution would discard all stdout without being CPU intensive and would not have delay loops. Also, I am not looking for an alternative solution using `expect` or any other external program. Is this a zsh or macOS bug? Can it be bypassed like dtrace restriction can be bypassed like [this](https://poweruser.blog/using-dtrace-with-sip-enabled-3826a352e64b) ? Though I would be surprised if it is SIP (System Integrity Protection) related.
Asked by codepoet (626 rep)
Dec 25, 2022, 11:01 AM
Last activity: Dec 26, 2022, 11:06 PM