Perl脚本和HTML与CGI之间的接口 [英] interface between perl script and HTML with CGI

查看:107
本文介绍了Perl脚本和HTML与CGI之间的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Perl和HTML的新手。我使用send expect语句在Perl中编写了后端脚本,用于循环和子例程。在Perl脚本中,我登录到服务器并发送一些命令并期待服务器提示并最终退出。现在,我正试图使用​​HTML将它带到前端。我使用CGI作为实现此目的的框架。这是我的代码部分

I am new to Perl and HTML . I have written a back end script in Perl using send expect statements, for loops and subroutines. In the Perl script i am logging in to the server and sending some commands and expecting server prompt and finally exit .Now i am trying to bring it to front end using HTML. I am using CGI as a framework to achieve this. This is my part of the code

#!/usr/bin/perl

use Expect;
use Switch;
use warnings;
use 5.008;
use Data::Dumper;
use CGI;

my $q = CGI->new;

my %data;
$data = $q->param('server');
print $q->header;


if($data eq 'null')
{
    print '<p> please select a server</p>';
    exit;

}


### 


    $exp->spawn($command, @parameters)
        or die "Cannot spawn $command: $!\n";

      $exp->send("string\n");


      $exp->expect($timeout, @match_patterns);


      $exp->expect($timeout,
               [ qr/regex1/ => sub { my $exp = shift;
                         $exp->send("response\n");
                         exp_continue; } ],
               [ "regexp2" , \&callback, @cbparms ],
              );


      $exp->soft_close();

这些是发送期望命令iam用于登录到服务器和发送命令的示例。但我在浏览器中看到他们将如何登录。但我不希望这些在浏览器上看到,但他们仍然应该在后台执行

these are the examples of send expect commands iam using to logging in to server and sending commands. but i am seeing them in the browser how they ll login . but i dont want these to be seen on browser but they should still execute in background

####

print "<html><head><title>Hello World</title></head>\n";
print "<body>\n";
print '<script>checked = false;function checkedAll () {if (checked == false){checked = true}else{checked = false}for (var i = 0; i < document.getElementById("sel").elements.length; i++) {document.getElementById("sel").elements[i].checked = checked;}}</script>';
print '<form action="robostats.pl " method="POST" id="sel">';
print '<input type="checkbox" onClick="checkedAll()">Select All<br />';

foreach my $i (@entire_success) {
    print '<input type="checkbox" name="sel" value="';
    print $i;
    print '">';
    print $i;
    print '<br />';
}

print '<input type="submit" value="submit">';
print '</form>';
print "</body></html>\n";

所以当我试图在浏览器中运行这些发送期望命令时,服务器登录提示全部到来在浏览器上。我不希望他们在浏览器上(他们应该只能进入控制台),我只想捕获其数组中的输出并在浏览器上显示表单的复选框。请帮助我如何实现这一目标。
谢谢

so when i am trying to run in the browser those send expect commands, server login prompts are all coming on the browser . I dont want them to be on the browser(they should only come in the console), I only want to capture its output in an array and display the checkboxes of the form on the browser. Please help me o how to achieve this. Thank you

推荐答案

您可能需要在Expect脚本开始时关闭命令的记录/回显,像这样:

You probably need to turn off logging/echoing of commands at the start of your Expect script, like this:

$exp->log_user(0);

这篇关于Perl脚本和HTML与CGI之间的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆