|
From: Todd R. <ros...@xi...> - 2002-01-16 00:32:44
|
I'm am trying to use Expect in a CGI program and am having strange
results. Here is a very much stripped down version of my code. It is
just for example purposes. I would expect to get a page with a "Go"
button and when I press it I would see
staring spawn (ls)
spawn done
Listing: <listing>
<GO>
instead I see
staring spawn (ls)
Content-type: text/html staring spawn (ls)
spawn done
Listing: <listing>
<GO>
Its like the whole program is starting over the first time it sees the
spawn line but the command is only being executed once. Any idea
what's going on?
#!/var/yp/bin/perl
use CGI;
use Expect;
$Expect::Log_Stdout=0;
$query = new CGI;
$formAction=$query->url();
$action=$query->param('action');
print "Content-type: text/html\n\n";
if ($action eq "Go") {
$cmd="ls";
print "spawn starting ($cmd)<BR>\n";
$run = Expect->spawn("$cmd");
print "spawn done<BR>\n";
$run->expect(10,'-re','.*');
print "Listing: " . $run->match(). "<BR>\n";
};
print "<BR><FORM action=$formAction METHOD=post>\n";
print "<INPUT TYPE=submit name=action value=Go><BR><BR>\n";
- Todd
|