Home > Archive > PERL Programming > April 2004 > weird CGI script output
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
weird CGI script output
|
|
| Mothra 2004-04-16, 10:31 am |
| Strange one this (to me at least): I've got a CGI script that enables help
desk people to restart software on remote servers (scary, I know, but i
couldn't refuse the task).
I got it set up so that they could press a button, this would post the
required form parameters to another page that would actually do the dirty
work, then print out the command-line output. Then it redirects back to the
original page so they can run it again.
However one of the lines on the 'results' page is printed twice if I break
up the HTML output with an if statement. I wanted the if statment after the
two print statements (see below for code)so that something would be
displayed on the page while the 'restart' function is running. The restart
function simply SSHs to a server runs some commands and captures the output
via session->reader in IO::Pipe.
But I get the following output on the screen:
--------------------------------------------------------------
Command-line output:
Content-Type: text/html; charset=ISO-8859-1
Command-line output:
[Fri Apr 16 14:22:08 BST 2004] Running restart on server4.address.com...
[Fri Apr 16 14:22:08 BST 2004] Finished restart on server4.address.com.
Now redirecting you back to the control panel...
--------------------------------------------------------------
i.e. the line "Command-line output" is printed twice with a "Content-Type"
line in between.
Can anyone explain why?
BTW, the code is this:
print
$q->header,start_html(-head=>meta({-http_equiv=>'Refresh', -content=>'10;U
RL=/cgi-bin/fast_restart.cgi'}));
print $q->h4("Command-line output:");
# Check to see which parameter we have been called with
if ($q->param("server1")) { @output=restart('10.0.0.1') }
elsif ($q->param("server2")) { @output=restart('10.0.0.2') }
elsif ($q->param("server3")) { @output=restart('10.0.0.3') }
elsif ($q->param("server4")) { @output=restart('10.0.0.4') }
foreach (@output) { print $q->p("$_") }
print "\n\nNow redirecting you back to the front page...\n";
print $q->end_html;
| |
| Matt Garrish 2004-04-18, 2:30 am |
|
"Mothra" <mothra@mothra.pub> wrote in message
news:c5omts$mce$1@newsg1.svr.pol.co.uk...
>
> i.e. the line "Command-line output" is printed twice with a "Content-Type"
> line in between.
> Can anyone explain why?
>
> BTW, the code is this:
>
I tried running the code you posted and I don't get the duplicate line you
indicate. If I had to guess, I would suspect that you've overlooked another
print statement somewhere in your code (a conditional being run that you
didn't think was being run, for example). Unless the output buffer isn't
being flushed properly, the first printing of that line must occur before
you output the header (meaning somewhere in the code you haven't posted).
Matt
| |
| Joe Smith 2004-04-18, 4:30 am |
| Mothra wrote:
> However one of the lines on the 'results' page is printed twice
>...
> if ($q->param("server1")) { @output=restart('10.0.0.1') }
Having lines go to STDOUT is a common bug when forks are involved.
It happens when an output buffer is flushed by both the parent
and a child. Do you have $|=1 at the top of your program?
-Joe
| |
| Mothra 2004-04-19, 4:31 am |
| "Joe Smith" <Joe.Smith@inwap.com> wrote in message
news:Haqgc.8409$hw5.6150@attbi_s53...
> Mothra wrote:
>
> Having lines go to STDOUT is a common bug when forks are involved.
> It happens when an output buffer is flushed by both the parent
> and a child. Do you have $|=1 at the top of your program?
> -Joe
Thank you! Yes that was it.
:-$
|
|
|
|
|