Sujet : Re: Faking a TTY on a pipe/socketpair
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.programmerDate : 16. Nov 2024, 21:51:28
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vhb0kg$ih4k$1@news.xmission.com>
References : 1
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
vh9vgr$5bb$1@dont-email.me>, <
Muttley@dastardlyhq.com> wrote:
There is a command line util (MacOS "say")* that I wish to use fork-exec'd from
my own program and send data to it via a socket created by socketpair().
Unfortunately "say" behaves differently depending on whether its stdin is
attached to a tty or not (and there's no cmd line option to prevent this).
With the former it'll speak after every newline, with the latter not until it
gets an EOF and I'd rather not do a fork-exec for each individual word or
phrase that needs to be spoken.
>
So my question is - is there a way to set up a pipe or socketpair** so that
it appears to be a tty from the exec'd programs point of view, eg ttyname()
returns non null?
I think the short answer to your question is: No.
There's no way to directly do what you want in a clean way.
Thus, all we have is kludgey workarounds. And I'm sure you've got plenty
of your own kludgey workarounds; you don't need any more from me.
That said, if was me, I'd use Expect. A few lines of Expect would do it,
such that I could send text to the process and the process would think they
were coming from a tty. In fact, if you don't want to learn Expect (i.e.,
Tcl) just for this project, I think just using "unbuffer -p" (unbuffer is a
program that comes with the Expect distribution) would do it for you.
If you want a more integrated Expect solution, there is a way to embed
Expect inside of your C program (i.e., link to it as a DLL instead of via
TCL scripting). I've never done this because I've never had the need, but
it might be closer to what you want.
Another way might be to write an interposer so that you could fool the
"say" program into thinking it was talking to a tty even if it wasn't. I
haven't done any Mac programming in a long time (since my Mac stopped
working), but I think interposers were do-able in the Mac ecosystem.
-- Many North Koreans believe Kim-il-Sung is an "almighty god" who "createdthe world" in seven days as a divine spirit millions of years ago, andcame to Earth as a human in 1912 as a messianic figure.