public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* piping input to executable reading from /dev/tty?
@ 2012-06-20 16:34 Dan B.
  2012-06-20 16:41 ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Dan B. @ 2012-06-20 16:34 UTC (permalink / raw)
  To: Cygwin-L

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

If so, can it be done with existing commands used in a script (as
opposed to via lower-level programming)?  (Can pseudoterminals be
set up/created/whatever via existing commands, or only via library
calls?)

Thanks,
Daniel





--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: piping input to executable reading from /dev/tty?
  2012-06-20 16:34 piping input to executable reading from /dev/tty? Dan B.
@ 2012-06-20 16:41 ` Eric Blake
  2012-06-20 21:22   ` Dan B.
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2012-06-20 16:41 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 741 bytes --]

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@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: piping input to executable reading from /dev/tty?
  2012-06-20 16:41 ` Eric Blake
@ 2012-06-20 21:22   ` Dan B.
  2012-06-20 21:26     ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Dan B. @ 2012-06-20 21:22 UTC (permalink / raw)
  To: cygwin

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





--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: piping input to executable reading from /dev/tty?
  2012-06-20 21:22   ` Dan B.
@ 2012-06-20 21:26     ` Eric Blake
  2012-06-21 11:35       ` Earnie Boyd
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2012-06-20 21:26 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1600 bytes --]

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
cygwin-specific, so you may get better support by looking for help on
using 'expect'.

-- 

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




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: piping input to executable reading from /dev/tty?
  2012-06-20 21:26     ` Eric Blake
@ 2012-06-21 11:35       ` Earnie Boyd
  0 siblings, 0 replies; 5+ messages in thread
From: Earnie Boyd @ 2012-06-21 11:35 UTC (permalink / raw)
  To: cygwin

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
> information that you wrote into your expect script.  This is not
> cygwin-specific, so you may get better support by looking for help on
> using 'expect'.

A word of caution, do not expect expect to function properly to a
native (non-Cygwin) process. The PTY emulation cannot support it.

-- 
Earnie
-- https://sites.google.com/site/earnieboyd

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-06-21 11:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-20 16:34 piping input to executable reading from /dev/tty? Dan B.
2012-06-20 16:41 ` Eric Blake
2012-06-20 21:22   ` Dan B.
2012-06-20 21:26     ` Eric Blake
2012-06-21 11:35       ` Earnie Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).