Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

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();

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

share|improve this question
    
Have you tried log_user 0 in the expect script? It turns off logging of commands and results. – Mark Setchell Mar 7 '14 at 9:29
    
By the way, your script is kind of littered with print statements, you might consider using "here" documents to improve clarity and performance, e.g. print<<EOF<html><head>..... EOF – Mark Setchell Mar 7 '14 at 9:39
    
no i havent tried . I dont know how to use it . Should i include before use Expect statements??? @MarkSetchell – user3095218 Mar 7 '14 at 9:49
    
@MarkSetchell i just used it but it is giving internal server error , if i remove log_user 0 . i am seeing all my login details and prompts where the commands go. Pls help me – user3095218 Mar 7 '14 at 9:59
    
It should be the first Expect command. – Mark Setchell Mar 7 '14 at 10:03

1 Answer 1

up vote 1 down vote accepted

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

$exp->log_user(0);
share|improve this answer
    
I want to log what is happening and store it in a file . Is this possible here ? – user3095218 May 21 '14 at 8:16
    
Try this $exp->log_file("$host.log"); – Mark Setchell May 21 '14 at 8:26
    
where will it be saved? – user3095218 May 21 '14 at 8:38
    
I think it comes out in "real time" - you may have to try changing the other line to $exp->log_user(1) to re-enable messages since it turned them off for you before. – Mark Setchell May 21 '14 at 8:41
    
I want $exp->log_user(0) to diable messages , but still want a log to be created :( – user3095218 May 21 '14 at 9:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.