Sujet : Re: Faking a TTY on a pipe/socketpair
De : janis_papanagnou (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.programmerDate : 18. Nov 2024, 03:38:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vhe9aa$ufh7$1@dont-email.me>
References : 1
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 16.11.24 12:26,
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.
On shell level I'm using a program called 'pty' that takes the command
as argument to make it think it has a terminal connection. Say, instead
of calling (forking) your 'say' command you're calling (forking) the
'pty' command with your 'say' command provided as argument. And all the
gory details are kept inside the 'pty'. - I forgot whether 'pty' came
with my Linux system, or whether I downloaded it separately, or whether
I implemented or adapted the version that is published in Stevens' APUE
book (with the source code available online, IIRC). IME it's worthwhile
to have such a tool at hand; it's useful to me for various application
contexts, and the interface is clean, a separate small tool unnecessary
to be merged on source code level, and simple to use.
I've just tried it (on shell level)... (less than 2 minutes effort...)
* Download the APUE examples:
http://www.apuebook.com/src.3e.tar.gz * Enter the pty directory and call "make" to get the 'pty' program
* To test it try, e.g.: "ls", "ls | cat -", and, "./pty ls | cat -"
Disclaimer: I have used 'pty' from shell only, but given what I faintly
recall from the mechanisms documented in Stevens' book I'd expect it to
work transparently also from a fork/exec'ed pipe-connected context.
If you'll try it I'd be interested in feedback, how/whether it works in
your fork/exec context with 'say'.
Janis
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?
* The MacOS speech API is Objective-C only and completely obtuse.
** Yes I know about the master-slave ptm,pts approach and I have done that in
the past but its complete overkill for this purpose.
Thanks for any help