asha_mail has asked for the wisdom of the Perl Monks concerning the following question:

I have one perl script file with following code

main.pl

#!/usr/bin/perl use strict; use warnings; use CGI qw(:all); #Create a new CGI object my $cgi = new CGI; print "Content-type:text/html\n\n"; print <<EndOfHTML; <center><<strong class="highlight"> SOFTWARE DIAGNOSTIC </strong>></ce +nter><head><title>Generating Self-Referential URLs</title></head> <body> <br><br> <center> <a href="progress_bar.pl"><img src="/images/diagnostics-icon.jpg" alt= +"SoftDiagno" width="800" height="450"></a> </center> </body> EndOfHTML

Progress_bar.pl

#!/usr/bin/perl use Tk; use Tk::ProgressBar; use strict; use CGI qw(:all); my $percent_done = 0; my $cgi = new CGI; print "Content-Type: text/html \n\n"; my $mw = MainWindow->new; my $text = "Percentage to date: $percent_done"; $mw->title('Progress Bar'); my $message = $mw->Message(-textvariable => \$text, -width => 130, -border => 2); my $progress = $mw->ProgressBar( -width => 30, -from => 0, -to => 100, -blocks => 50, -colors => [0, 'green', 50, 'yellow' , 80, 'red'], -variable => \$percent_done )->pack(-fill => 'x'); my $exit = $mw->Button(-text => 'Exit', -command => [$mw => 'destroy']); my $get = $mw->Button(-text => 'Press to start!', -command => \&start); $get->pack; $message->pack; $exit->pack; MainLoop; sub start { for ($percent_done=0; $percent_done <= 100; $percent_done +=20) { $text = "Loading: $percent_done%"; $mw->update; sleep 1; } $text = 'Done!'; $mw->update; }

When Progress_Bar.pl file is called its showing blank page in browser.How to display the output of Progress_Bar.pl in main.pl when the image is clicked?

Replies are listed 'Best First'.
Re: Display perl code output in CGI script
by Anonymous Monk on Dec 21, 2011 at 07:56 UTC

      Instead of taking screenshots I actually want the window of Progress_bar.pl to run.

        This is not possible. Browsers do not support Tk.
        Update: The CGI script runs on the server. It sends data to the client - a browser. What data do you imagine being sent to a browser to make it show the Tk application?

        Instead of taking screenshots I actually want the window of Progress_bar.pl to run.

        Um, whose screenshots do you think you'll be taking?

        The Progress_bar.pl will run on the server, and main.pl will be taking screenshots of Progress_bar.pl

        Progress_bar.pl doesn't run in the browser, or the browsers computer (client), it runs on the same computer main.pl runs, it runs on the server

        If you want the browser computer (client) to run a program, they'll need to have perl installed, and browser configured to execute any perl programs downloaded ... or browser configured to execute any .exe files downloaded, and you send them a PAR::Packer/pp-packed perl program (or using perlapp or perl2exe...)

        See the above links I provided, watch the video, read the tutorials, learn how the internet works :)