[Israel.pm] Using Expect

Madani, Srikanth, VF-DE Srikanth.Madani at vodafone.com
Mon Mar 13 07:41:10 PST 2006


FYI, I managed to use Expect.pm to solve the following problem
(discussed earlier, thread called "Coroutines in Perl"):

> So my Perl code must not only call rcs with options -u12.1.1 hello.c,
> but also supply the needed 'y' character and '.' + 'carriage return'.

Here's sample code:

        my $rcs_program = "/usr/local/bin/rcs"; # The interactive
program to be dealt with in a non-interactive way
        my @rcs_params  = ("-u$branch", "$RCS_file"); # Options and
argument file
        my $exp = Expect->spawn($rcs_program, @rcs_params ) || 
			die "\nError: failed to spawn $rcs_program with
parameters @rcs_params: $!\n";
        my $response = "y\n.\n"; # Answer (y)es to a question, press
enter, single dot, enter again
        $exp->send($response);
        $exp->soft_close();
	  my $prog_failed = $exp->exitstatus();
	  if ($prog_failed) {
			print "\nError: call to $rcs_program @rcs_params
failed.";
	  }

While running under the "use diagnostics" pragma, I get the following
warning (Perl 5.005_03 on Solaris):
[These warnings don't occur on Perl v5.8.1 on GNU/Linux.]

Use of uninitialized value in ioctl at
 
/opt/perl5.8.6/lib/site_perl/5.8.6/sun4-solaris-thread-multi/IO/Pty.pm
line 119 (#1)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a
mistake.
    To suppress this warning assign a defined value to your variables.

    To help you figure out what was undefined, perl tells you what
operation
    you used the undefined value in.  Note, however, that perl optimizes
your
    program and the operation displayed in the warning may not
necessarily
    appear literally in your program.  For example, "that $foo" is
    usually optimized into "that " . $foo, and the warning will refer to
    the concatenation (.) operator, even though there is no . in your
    program.

warning: TIOCSCTTY failed, slave might not be set as controlling
terminal: Invalid argument at
/opt/VFD2tools/perl5.8.6/lib/site_perl/5.8.6/sun4-solaris-thread-multi/I
O/Pty.pm line 120.


I got rid of it by commenting out use diagnostics ;-).





Best regards,
Srikanth Madani

That is the true season of love, 
when we believe that we alone can love,
that no one could have loved so before us, 
and that no one will love in the same way as us.
 	-Johann Wolfgang von Goethe




More information about the Perl mailing list