Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Syntactic Confectionery Delight
 
PerlMonks  

RUN A FILE FROM HTML

by majo (Novice)
on May 10, 2012 at 11:44 UTC ( #969797=perlquestion: print w/ replies, xml ) Need Help??
majo has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone. Is it possible to run either of these codes from HTML Thanks majo

#!/usr//bin/perl -w use LWP::UserAgent; use Time::HiRes 'time','sleep'; $ua = LWP::UserAgent->new; $request = new HTTP::Request('GET', "http://http://www.computerhope.co +m/file.com"); $start = time( ); $response = $ua->request($request); $end = time( ); $latency = $end - $start; print length($response->as_string( )), " bytes received in $latency s +econds\n";
#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use LWP::UserAgent; my $urlin = shift || "http://zentara.net/zentara.avi"; my $infile = "zentara1.avi" ; print "gettin video file : $infile\n"; # don't buffer the prints to make the status update $| = 1; open(IN,"> $infile") or die "$_\n"; my $ua = LWP::UserAgent->new(); my $received_size = 0; my $request_time = time; my $last_update = 0; my $response = $ua->get($urlin, ':content_cb' => \&callback, ':read_size_hint' => 8192, ); print "\n"; close IN; #play the avi file with mplayer # system( "mplayer $infile" ); ############################################# sub callback { my ($data, $response, $protocol) = @_; my $total_size = $response->header('Content-Length') || 0; $received_size += length $data; # write the $data to a filehandle or whatever should happen # with it here. print IN $data; my $time_now = time; # this to make the status only update once per second. return unless $time_now > $last_update or $received_size == $total_s +ize; $last_update = $time_now; print "\rReceived $received_size bytes"; printf " (%i%%)", (100/$total_size)*$received_size if $total_size; printf " %6.1f/bps", $received_size/(($time_now-$request_time)||1) if $received_size; } __END__

Comment on RUN A FILE FROM HTML
Select or Download Code
Re: RUN A FILE FROM HTML
by tobyink (Prior) on May 10, 2012 at 13:55 UTC

    HTML is a document format, and as such doesn't "do" anything.

    It can contain instructions which when followed by a browser, can cause that browser to do something; or instructions that when followed by a browser, can cause the browser to ask a web server to do something.

    Please explain the end result you hope to achieve and we'll let you know the best way of achieving it.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Hi Tobylink. thanks for the reply What I want call the file from HTML. Is it possible to use hyperlink?The result I want is exactly the result I want when I run the file in perl that is ti print the result which is the latency result and also save this result into text or html file Thanks

        I think what you mean is that you want to make these scripts run on a web server and display their results on a web page. By the sounds of it you don't have a clear understanding of what server side scripting is, and what HTML is. There is a bit of a learning curve, I think the best place for you to start would be with Ovid's CGI Course (see also the Web Programming section of tutorials). Once you have specific questions please let us know what you need help with.

      hi can i use php execute the code given below and display the results on HTML?

      #!/usr//bin/perl -w use LWP::UserAgent; use Time::HiRes 'time','sleep'; $ua = LWP::UserAgent->new; $request = new HTTP::Request('GET', "http://http://www.computerhope.co +m/file.com"); $start = time( ); $response = $ua->request($request); $end = time( ); $latency = $end - $start; print length($response->as_string( )), " bytes received in $latency s

        Why would you want to use PHP to execute Perl code? Please take the advice given previously (in this thread) regarding displaying the results of your server side script within a web page.

        Update: Also http://http://www.computerhope.com/file.com isn't a valid URL.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://969797]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2013-05-24 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (495 votes), past polls