scott09 has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script calling an Expect script and want to pass a parameter from the Perl to the Expect but cannot. The perl script calls the Expect with: - system "./verify_findmissing.exp $host" - and the Expect starts with with: - spawn "/usr/bin/telnet" $host - I've tried variations on use of the $host varialbe but can't seem to get it right. I know it's something simple but it sure is driving me crazy!! Thanks for any help...Scott

Replies are listed 'Best First'.
Re (tilly) 1: Cannot pass arg from perl to expect
by tilly (Archbishop) on Jul 10, 2001 at 01:47 UTC
    Arguments to your Expect script are in the global array $argc. Grabbing an old Expect script, here is a sample of how you can manually process command-line arguments:
    set i 0 while {$i < $argc} { if ![string compare "-m" [lindex $argv $i]] { incr i if $i==$argc { send_user "-m specified without machine, FAILING" exit -3 } set machine [lindex $argv $i] } elseif ![string compare "-n" [lindex $argv $i]] { incr i if $i==$argc { send_user "-n specified without name, FAILING" exit -3 } set name [lindex $argv $i] } elseif ![string compare "-p" [lindex $argv $i]] { incr i if $i==$argc { send_user "-p specified without password, FAILING" exit -3 } set password [lindex $argv $i] } elseif ![string compare "-c" [lindex $argv $i]] { incr i if $i==$argc { send_user "-c specified without argument, FAILING" exit -3 } set cmd [lindex $argv $i] } incr i }
    Now Perl can pass things on the command line. I don't know enough TCL to know if there is a cleaner way to do this processing (I would *hope* that there is). But it works.

    Incidentally I would suggest that before hand-rolling a lot of Expect scripts that you look to CPAN for modules to drive the same things. For instance try Net::Telnet or failing that, Expect. Then you don't need to mix languages and error handling will probably be a bit easier as a result...

Re: Cannot pass arg from perl to expect
by lshatzer (Friar) on Jul 10, 2001 at 01:50 UTC
    I can think of two modules that might help you so you don't have to rely on another program.
    1. Expect
    2. Net::Telnet
    Or, inside expect, don't expect (pun intended) it to know that $host is what is passed in, use $argv (If I remember my Expect right).