使用Perl的期望

发布于 2025-02-14 00:13:08 字数 923 浏览 0 评论 0原文

我的情况是,在我调用以下perl脚本的情况下,

if (param("lremail") && param("lot")) {
    my $address=param("lremailaddress");
    my $lot=param("lot");
    print a({-href=>"$dir/new.pl"},"Back to Top"),br;
    print "Request submitted for $address.",br;
    print "Lot $lot",br;
    print "You will receive an e-mail with a link to the data when the request is complete.";
    print end_html;
    system ("ssh SERVERNAME /test/abc.csh $lot $$ $address &");
    exit(1);

上面的脚本不运行,因为当我执行系统时,请提示系统以获取密码。然后我查找它并找到了下面的命令。

> expect -c 'spawn ssh SERVERNAME /test/abc.csh J213520 06 [email protected] "ls -lh file"; expect "Password:"; send "PASSWORD\r"; interact'

上面的命令成功执行,没有任何问题,但仅从命令行中执行。当我将相同的(通过替换System调用)中时,它会失败。 如何将其合并到第一个脚本中?

I have a situation where in I am calling the below Perl script

if (param("lremail") && param("lot")) {
    my $address=param("lremailaddress");
    my $lot=param("lot");
    print a({-href=>"$dir/new.pl"},"Back to Top"),br;
    print "Request submitted for $address.",br;
    print "Lot $lot",br;
    print "You will receive an e-mail with a link to the data when the request is complete.";
    print end_html;
    system ("ssh SERVERNAME /test/abc.csh $lot $ $address &");
    exit(1);

The above script does not run because when I execute the system is prompted for a password. Then I looked it up and found the below command..

> expect -c 'spawn ssh SERVERNAME /test/abc.csh J213520 06 [email protected] "ls -lh file"; expect "Password:"; send "PASSWORD\r"; interact'

The above command is executed successfully without any issue but from the command line only. When I incorporate the same(by replacing the system call) within the Perl script, it fails.
How can I incorporate within the first script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救赎№ 2025-02-21 00:13:08

有一个期望 perl的模块。

但是,我倾向于编写直截了当的期望脚本,并从Perl打电话给它们。这样,我可以自己使用期望脚本。但是,我曾经做过很多TCL。

There's an Expect module for Perl.

However, I tend to write straight expect scripts and call them from Perl. That way I can use the expect scripts on their own. But then, I used to do a lot of Tcl too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文