Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print during processing of form

Status
Not open for further replies.

bluedragon2

IS-IT--Management
Jan 24, 2003
2,642
US
I a perl script with a simple html form. When it is executed, it works properly, but the results are not printed until it runs through the entire process. I would like it to print as it processes it that is possible. Here is part of the script:

Code:
[tt]
print header;
print "<FONT color=#006600><h1>BBS User Account Management</h1></FONT>\n";

print start_html('BBS Account Management'),
    start_form,
    "User Name: ",textfield(-name=>'Uname',-size=>15),
    p,
    radio_group(-name=>'ad',-values=>['Add Account','Delete Account','Change Password'],-default=>'Add Account'),
    p,
    "BBS Hostname: ",popup_menu(-name=>'Host',-values=>[@bbspop],-default=>'ALL'),
    p,
    "New Password: ",textfield(-name=>'Npass',-size=>15)," (Minimum 8 characters containing 1 upper, 1 lower, 1 number,
and 1 special)",
    p,
    "Execute Password: ",password_field(-name=>'Epass',-size=>8)," ",submit(-name=>'Execute'),
    end_form,
    hr;
if (param()) {
    $Epass = param(Epass);
    $Uname = param(Uname);
    $ad = param(ad);
    $Host = param(Host);
    $Npass = param(Npass);

    if ($Epass ne "XXX") {
        print "<FONT color=red><TT><B>Invalid Execute Password</B></TT></FONT>\n";
        exit;
    } else {
        print "<TT><B>Processing</B></TT>\n";
        print "<CENTER></CENTER>\n";
    }
[/tt]

The file goes on and has several lines of output, but will not print anything until it has completed.

Thanke


[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Is it not printing it at all or is all the text just showing up at the end?

$|=1; will solve it if it is just buffering till the end.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
It is buffering until the end. Where should the $|=1; be located, I tried it at the beginning of the script and after the if(param()) {



[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
put

$|=1;

before you start printing output.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Have tried it everywhere, but it is still buffering output,

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Is that the whole script?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
no, the whole script:

Code:
[tt]
#!/usr/bin/perl

use CGI qw(:standard);

$bbslist = "/opt/BBSacct/bbslist.txt";
$bbs = "/opt/BBSacct/bbsacct.exe";
@bbspop = ("ALL");
$| = 1;

open(BBSL,$bbslist);
@lines = <BBSL>;
close(BBSL);
foreach $line (@lines) {
    chomp($line);
    @s = split(/ /,$line);
    push(@bbspop,$s[0]);
}

print header;
print "<FONT color=#006600><h1>BBS User Account Management</h1></FONT>\n";

print start_html('BBS Account Management'),
    start_form,
    "User Name: ",textfield(-name=>'Uname',-size=>15),
    p,
    radio_group(-name=>'ad',-values=>['Add Account','Delete Account','Change Password'],-default=>'Add Account'),
    p,
    "BBS Hostname: ",popup_menu(-name=>'Host',-values=>[@bbspop],-default=>'ALL'),
    p,
    "New Password: ",textfield(-name=>'Npass',-size=>15)," (Minimum 8 characters containing 1 upper, 1 lower, 1 number,
and 1 special)",
    p,
    "Execute Password: ",password_field(-name=>'Epass',-size=>8)," ",submit(-name=>'Execute'),
    end_form,
    hr;

if (param()) {
    $Epass = param(Epass);
    $Uname = param(Uname);
    $ad = param(ad);
    $Host = param(Host);
    $Npass = param(Npass);

    if ($Epass ne "XXX") {
        print "<FONT color=red><TT><B>Invalid Execute Password</B></TT></FONT>\n";
        exit;
    } else {
        print "<TT><B>Processing</B></TT>\n";
        print "<CENTER></CENTER>\n";
    }
    stringcheck($Uname,"User Name");

    if ($Host ne "ALL") {
        open(BBSF,$bbslist);
        @lines = <BBSF>;
        close(BBSF);
        foreach $line (@lines) {
            chomp($line);
            $pc = `ping $Host`;
            if ($pc =~ /alive/) {
            } else {
                print "<FONT color=red><TT><B>Could not connect to $Host</B></TT></FONT>\n";
                print "<CENTER></CENTER>\n";
                exit;
            }
            @s = split(/ /,$line);
            $hc = $s[0];
            if ($Host =~ /$hc/) {
                $Pass = $s[1];
            }
        }
        if ($ad eq "Add Account") {
            stringcheck($Npass,"New Password");
            runexp($Host,$Pass,$Uname,$Npass,"a");
        }
        if ($ad eq "Delete Account") {
            runexp($Host,$Pass,$Uname,$Npass,"d");
        }
        if ($ad eq "Change Password") {
            stringcheck($Npass,"New Password");
            runexp($Host,$Pass,$Uname,$Npass,"d");
            runexp($Host,$Pass,$Uname,$Npass,"a");
        }
    } else {
        open(BBSL,$bbslist);
        @lines = <BBSL>;
        close(BBSL);
        foreach $line (@lines) {
            chomp($line);
            @s = split(/ /,$line);
            $Host = $s[0];
            $Pass = $s[1];
            $pc = `ping $Host`;
            if ($pc =~ /alive/) {
            } else {
                print "<FONT color=red><TT><B>Could not connect to $Host</B></TT></FONT>\n";
                print "<CENTER></CENTER>\n";
                next;
            }
            if ($ad eq "Add Account") {
                stringcheck($Npass,"New Password");
                runexp($Host,$Pass,$Uname,$Npass,"a");
            }
            if ($ad eq "Delete Account") {
                runexp($Host,$Pass,$Uname,$Npass,"d");
            }
            if ($ad eq "Change Password") {
                stringcheck($Npass,"New Password");
                runexp($Host,$Pass,$Uname,$Npass,"d");
                runexp($Host,$Pass,$Uname,$Npass,"a");
            }
        }
    }
}

sub stringcheck {
    my($nc,$em) = @_;
    if (length($nc) == 0) {
        print "<FONT color=red><TT><B>ERROR - Must input $em</B></TT></FONT>\n";
        exit;
    }
}

sub runexp {
    my($H,$P,$U,$N,$W) = @_;
    @f = `$bbs $H $P $U $W $N`;
    foreach $line (@f) {
        chomp($line);
        if ($line =~ /COMPLETE/) {
            @s = split(/Z/,$line);
            $em = $s[1];
            print "<FONT color=green><TT><B>$em Complete</B></TT></FONT>\n";
            print "<CENTER></CENTER>\n";
        }
        if ($line =~ /^ERROR/) {
            @s = split(/Z/,$line);
            $em = $s[1];
            print "<FONT color=red><TT><B>$em</B></TT></FONT>\n";
            print "<CENTER></CENTER>\n";
        }
    }
}
[/tt]

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
thinking this is impossible

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
it looks like it should work.. idk.. kinda confusing :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
read an article on perlmonks that said that you can not unbuffer loading a web page. Have to pull down that url, since I closed it before I could bookmark it.

I have tried about every unbuffer call that I could find to no avail. I can interupt it and print with flushing STDOUT, but it will quit running after that.

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
This script is running on a server with tomcat. I ran it on a server running apache and it did unbuffer.

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Is it possible to create the above web page and have the results printed to a text file. Then print that text file in a frame that refreshes every 5 seconds?

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
I do the same thing. Just use a refresh and have it call a perl script that reads the results.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Just tried it, and it still will not work...

Once I hit submit, the other frame will not refresh until the script is done running.

I am about to just let it go as is...

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
One thing, I just have $|=1, do I need to select the file handle first? Like:

open(TXTF,$file);
select(TXTF);$|=1;
print;
close(TXTF);

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
The frame option did work, I had a hung session on the last test. It works like a charm now...

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top