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...


In reply to Re (tilly) 1: Cannot pass arg from perl to expect by tilly
in thread Cannot pass arg from perl to expect by scott09

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.