help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to redirect tty to /dev/null?


From: Eric Blake
Subject: Re: [Help-bash] How to redirect tty to /dev/null?
Date: Tue, 3 Sep 2019 11:06:52 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

On 9/3/19 10:40 AM, Peng Yu wrote:
> Hi,
> 
> If I run the following command, it still asks the password in the
> screen. I suspect that somehow the pass is taken from tty instead of
> stdin.

strace would confirm that. But you are probably right.

> Does anybody know how to redirect tty to /dev/null?

All processes have a notion of a controlling terminal.  If you want a
child process' interaction with its controlling terminal to behave
differently than interacting with YOUR controlling terminal, then you
need to open up a pty and become the master of that device prior to
spawning your child process, at which point your child process's tty is
now the slave end of the pty you just opened.  At that point, as master
of the pty you can do whatever you want with the child's interactions
with its controlling terminal (including blindly ignoring whatever the
child wants to output to its tty, for the effect of that output going to
/dev/null).  Look at the 'expect' program if you want a demonstration of
creating your own pty for managing terminal interactions of child
processes.  But that starts to get into the scope of pty management, and
less about bash, so it becomes questionable that you'll get any better
help on this topic from this list.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]