in reply to Re^3: Automating command line utility
in thread Automating command line utility

I'm a bit confused. In the post I responded to you, you say applications often read the password directly from the terminal - and that you need 'expect' for it.

And if I respond that on Linux, one doesn't need 'expect' to read from the terminal, you argue that the OP also wants to supply data. Why did you bring up the issue of reading from the terminal then?

As for reading/writing to the same device, I never talked about writing to /dev/tty. All I said was reading. Which is as simple as:

open my $tty, "<", "/dev/tty" or die; while (<$tty>) { chomp; print "Read '$_' from the terminal\n"; }
since that isn't any harder than reading from a file, I would recommend that over learning expect.

Replies are listed 'Best First'.
Re^5: Automating command line utility
by salva (Canon) on Oct 03, 2008 at 11:13 UTC
    Think about the following scenario:

    There is the binary utility su, that you want to automate from a Perl script. For instance, you want to run  su -c "make install"

    You write a script that just does system 'su -c "make install"'. But when you run it, it asks for a password, so you try...

    open my $pipe, '| su -c "make install"'; print $pipe, "$password\n";
    But it keeps asking for the password because su is reading from /dev/tty.

    What do you do then?

      Ah, I understand now. I though moritz was talking about having to read password in the application being written. But he was talking about whatever other program that needs to be run.

      Which makes all my comments moot.

Re^5: Automating command line utility
by moritz (Cardinal) on Oct 05, 2008 at 17:39 UTC
    If you want to automate a program that reads a password from the terminal, it won't help you at all if you open /dev/tty for reading - or am I missing some crucial point here?.

    Update: Just read the other replies to parent post, so never mind.