Dan B. | 20 Jun 2012 18:33

piping input to executable reading from /dev/tty?

Is there any way to redirect /dev/tty similarly to how stdin can be
redirected (e.g., like "echo ... | someexecutable")?

I'm working with an executable (openssl in ocsp mode) that reads a
password via /dev/tty (instead of stdin) because normally it wants to
get that password from the user even if the user invoked the executable
by running a script (and because it uses stdin for data input).  (I can
see the use of /dev/tty by using strace.)

However, I'm trying to invoke that executable from a script and have it
run non-interactively.  (It's an example/test script that should be
interactive and does not need to be secure.)

Other OpenSSL subcommands like "openssl ca" and "openssl req" have
command-line options for specifying passwords non-interactively.
However, the "openssl ocsp" subcommand does not, so I'm trying to find
some other way to suppress the interactive prompting for the password.

VMS's equivalent of /dev/tty was its environment variable SYS$COMMAND.
SYS$COMMAND by default continued to refer to the interactive terminal
even when SYS$INPUT (VMS's equivalent to the stdin descriptor) was
redirected.  Therefore, scripts could read from SYS$COMMAND when they
wanted to read something that normally came from the user even when
standard input was redirected.

However, a second script calling that first script could specifically
set SYS$COMMAND if it wanted to non-interactively provide that input
that the first script expected to normally come from the user.

Does Cygwin (or Unix/Linux, for that matter) have any equivalent way
(Continue reading)

Eric Blake | 20 Jun 2012 18:41
Picon
Favicon
Gravatar

Re: piping input to executable reading from /dev/tty?

On 06/20/2012 10:33 AM, Dan B. wrote:
> Is there any way to redirect /dev/tty similarly to how stdin can be
> redirected (e.g., like "echo ... | someexecutable")?

Yes; use 'expect'.

> Does Cygwin (or Unix/Linux, for that matter) have any equivalent way
> of redirecting /dev/tty?
> 
> Can /dev/tty be redirected at all?  (I would guess that something
> could be done with pseudoterminals, but I know very little about
> them.)

Yes, 'expect' is the command line tool that lets you script around
programs that expect to be run interactively, but where you want to
script the input that your program will see.

--

-- 
Eric Blake   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Dan B. | 20 Jun 2012 23:20

Re: piping input to executable reading from /dev/tty?

Eric Blake wrote:
> On 06/20/2012 10:33 AM, Dan B. wrote:
>> Is there any way to redirect /dev/tty similarly to how stdin can be
>> redirected (e.g., like "echo ... | someexecutable")?
> 
> Yes; use 'expect'.
> 
>> Does Cygwin (or Unix/Linux, for that matter) have any equivalent way
>> of redirecting /dev/tty?
>>
>> Can /dev/tty be redirected at all?  (I would guess that something
>> could be done with pseudoterminals, but I know very little about
>> them.)
> 
> Yes, 'expect' is the command line tool that lets you script around
> programs that expect to be run interactively, but where you want to
> script the input that your program will see.

Does expect use only redirection of file descriptors, or can it also
redirect references to /dev/tty?

Daniel

Eric Blake | 20 Jun 2012 23:25
Picon
Favicon
Gravatar

Re: piping input to executable reading from /dev/tty?

On 06/20/2012 03:20 PM, Dan B. wrote:
> Eric Blake wrote:
>> On 06/20/2012 10:33 AM, Dan B. wrote:
>>> Is there any way to redirect /dev/tty similarly to how stdin can be
>>> redirected (e.g., like "echo ... | someexecutable")?
>>
>> Yes; use 'expect'.
>>
>>> Does Cygwin (or Unix/Linux, for that matter) have any equivalent way
>>> of redirecting /dev/tty?
>>>
>>> Can /dev/tty be redirected at all?  (I would guess that something
>>> could be done with pseudoterminals, but I know very little about
>>> them.)
>>
>> Yes, 'expect' is the command line tool that lets you script around
>> programs that expect to be run interactively, but where you want to
>> script the input that your program will see.
> 
> Does expect use only redirection of file descriptors, or can it also
> redirect references to /dev/tty?

expect uses pseudoterminals so that the stdin of the child process is
also its /dev/tty (remember, /dev/tty is a magic name that resolves to
the current controlling terminal, and that a pseutoterminal can be a
controlling terminal).  Therefore, anything that normally requires you
to interactively type something because the child process opened
/dev/tty can be run under expect, where opening /dev/tty in the child
will now be asking expect for the input, and expect then hands it the
information that you wrote into your expect script.  This is not
(Continue reading)

Earnie Boyd | 21 Jun 2012 13:34
Picon

Re: piping input to executable reading from /dev/tty?

On Wed, Jun 20, 2012 at 5:25 PM, Eric Blake wrote:
> On 06/20/2012 03:20 PM, Dan B. wrote:
>> Eric Blake wrote:
>>> On 06/20/2012 10:33 AM, Dan B. wrote:
>>>> Is there any way to redirect /dev/tty similarly to how stdin can be
>>>> redirected (e.g., like "echo ... | someexecutable")?
>>>
>>> Yes; use 'expect'.
>>>
>>>> Does Cygwin (or Unix/Linux, for that matter) have any equivalent way
>>>> of redirecting /dev/tty?
>>>>
>>>> Can /dev/tty be redirected at all?  (I would guess that something
>>>> could be done with pseudoterminals, but I know very little about
>>>> them.)
>>>
>>> Yes, 'expect' is the command line tool that lets you script around
>>> programs that expect to be run interactively, but where you want to
>>> script the input that your program will see.
>>
>> Does expect use only redirection of file descriptors, or can it also
>> redirect references to /dev/tty?
>
> expect uses pseudoterminals so that the stdin of the child process is
> also its /dev/tty (remember, /dev/tty is a magic name that resolves to
> the current controlling terminal, and that a pseutoterminal can be a
> controlling terminal).  Therefore, anything that normally requires you
> to interactively type something because the child process opened
> /dev/tty can be run under expect, where opening /dev/tty in the child
> will now be asking expect for the input, and expect then hands it the
(Continue reading)


Gmane