开发者

Can I call an Expect script from Perl by passing an array as a parameter?

Is it possible to call an Expect script from Perl by passing an array as a parameter? If so, how to retrieve that array in Expect like we retrieve non-array data as:

set 开发者_如何学编程value [lindex $argv 0]


I assume you're talking about a Perl array, which is known as a list in Tcl. From Perl:

system 'myscript.exp', @ary;

Then your Expect script will have:

set list_of_arguments $argv


Glenn, I wonder whether Saranyya will understand your answer. I'll offer a bit of background that might help him.

First, Saranyya, be aware that you can choose a variety of different combinations of Perl and Expect. If an existing Expect script does something you want to enhance, you might do well simply to code the functionality in Expect, rather than Perl; Expect is a fully-general-purpose language, and can do essentially everything Perl does.

Conversely, if you have a Perl application which needs Expect functionality, you can almost surely write everything you need in Perl, with Expect.pm; there's no need to construct a separate Expect process.

Finally, it's also reasonable to do what you seem to describe, and what Glenn believes you're after: invocation of a stand-alone Expect process from Perl. If you do so, and if, as Glenn sketches, your Perl program includes

system 'myscript.exp', @ary;

then your Expect script accesses the parameters passed to it through the $::argv value, which is a list. I'll elaborate the example slightly: suppose you pass through system a list of hostnames; then in Expect you might usefully have

set list_of_hostnames $::argv
foreach hostname $list_of_hostnames {
    do_something_valuable $hostname
}

The interface from one process to another communicates values, rather than variables. By the time the information reaches Expect, it "doesn't know" that it was an array (for example) in Perl. You use the same techniques to dereference $::argv, however you packed things on the Perl side.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜