The functionality which you seek is provided by the Expect module. For example:
use Expect;
my $process = Expect->spawn( '/usr/bin/passwd');
$process->expect( 10, "Password:" );
$process->send( "changeme\n" );
$process->send( "newpass\n" );
$process->send( "newpass\n" );
$process->expect( undef );
Alternatively, if you find the interface to this module overly complex, you may want to investigate the Expect::Simple module.
perl -le 'print+unpack("N",pack("B32","00000000000000000000001000000100"))' | [reply] [d/l] |
The Expect module mentioned above is the usually best approach for working with interactive processes. It is well designed for dealing with interactive processes, handling deadlocks and situations where you have some input that is expected, an unexpected error, or nothing at all returns.
Another way to work with interactive processes is IPC::Open2. Using IPC::Open2 will give you a read and a write handle to a process. It should be included as a standard module, so it does not require installing a new module. But using it can degenerate quickly if you get unexpected errors or no output from a program, so you need to program carefully to avoid deadlocks. I would recommend you use Expect if at all possible.
| [reply] |
You could use backtics `mysql -u root -ppassword somedb` or system using the single or multi arg syntax or Expect.pm What is best (and/or will work) depends on what you are trying to do with what external executable and if security is a major or minor issue.
For many things you might do via system there is a Perl equivalent or interface just to add to the options.
doc
| [reply] [d/l] |