Deutsch   English   Français   Italiano  
<vhe9aa$ufh7$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Janis Papanagnou <janis_papanagnou@hotmail.com>
Newsgroups: comp.unix.programmer
Subject: Re: Faking a TTY on a pipe/socketpair
Date: Mon, 18 Nov 2024 03:38:01 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <vhe9aa$ufh7$1@dont-email.me>
References: <vh9vgr$5bb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Nov 2024 03:38:02 +0100 (CET)
Injection-Info: dont-email.me; posting-host="da8dc5b53507b46ac4f1202689067d91";
	logging-data="998951"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/ZB8uh9RKbS+7fouov5MeS"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.11.0
Cancel-Lock: sha1:a7DHyobQzW8CcID6+tGpDIX+MwM=
In-Reply-To: <vh9vgr$5bb$1@dont-email.me>
Content-Language: en-US
Bytes: 3447

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