in reply to Automating command line utility

Most programs that read passwords don't read them from the standard input, but try to read directly from the terminal. If that's the case, you need expect (or something similarly ugly) for that.

Replies are listed 'Best First'.
Re^2: Automating command line utility
by JavaFan (Canon) on Oct 03, 2008 at 09:27 UTC
    The OP said he was using Linux. In that case, one can simple open /dev/tty and read from it. This reads from the terminal - no expect needed.
      one can simple open /dev/tty and read from it

      I don't think so, opening /dev/tty is useful, for instance, when you want to ask the user for a password and don't want it comming from stdin, but the OP seems to be automating some program that asks for login/passwd probably via its /dev/tty and that's what Expect is for.

      Under the hood, Expect creates a pair of master/slave pseudo ttys (via IO::Pty), forks a new process and sets /dev/tty on the child to be the slave pseudo tty. Then the parent process, through the master pty, can read and write to the child /dev/tty.

      It's not done with reading form /dev/tty, sine satyakm also wants to supply data. And reading from and writing to the same device isn't something that I'd recommend a beginner to do himself, which is why I recommended using something that wraps that process for him/her.
        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.