Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

To call a .pl file when a button is pressed on a GUI created using Perl CGI

by pratibha.blr (Initiate)
on Sep 24, 2013 at 12:01 UTC ( #1055479=perlquestion: print w/replies, xml ) Need Help??
pratibha.blr has asked for the wisdom of the Perl Monks concerning the following question:

I have created a GUI using Perl CGI on which some buttons are there like "OFF" and "ON". And I have created a .pl file. The pl file is working perfectly fine when I run it on CLI. But when I program the buttons of the cgi file to call the pl file. It is not even opening on the GUI. My approach is: 1. A cgi file is there. On which OFF/ON buttons are there. 2. A text file is there which has information of some certain parameters of a resource like: Name, IP, ON/OFF etc. 3. A change.pl file is there which when called will change ON/OFF parameter of a particular resource. 4. Now what I want is that when I call the ON/OFF button in front of a Resource named A, the change.pl file is called and then it will change the text.txt file by replacing ON to OFF or vice versa. What I am able to do: When I call the button it prints the name of the resource and the value to be changed and value which I want to be used by change.pl and change the value in .txt file.' But I not able to run the .pl file whenever a certain button is pressed.
  • Comment on To call a .pl file when a button is pressed on a GUI created using Perl CGI

Replies are listed 'Best First'.
Re: To call a .pl file when a button is pressed on a GUI created using Perl CGI (webserver)
by Anonymous Monk on Sep 24, 2013 at 12:12 UTC
Re: To call a .pl file when a button is pressed on a GUI created using Perl CGI
by ww (Archbishop) on Sep 24, 2013 at 12:18 UTC
    • Please show your code (or, more precisely, minimal samples of code and data that illustrate the problem). My telepathy module is broken. SeeI know what I mean. Why don't you?.
    • Please divide your exposition into paragraphs -- one per idea -- using markup: para (<p>...</p>) tags. Doing so would make your very dense explanation more accessible.
    • Please include any error messages, warnings and/or error-log entries.

      One text file is present:

      system1,10.111.23.45,OFF,powered-off

      system2,10.111.23.46,ON,used

      system3,10.111.23.47,OFF,idle

      One CGI file is written which reads the above text file and prints on the GUI. If for system1 OFF is present in text file on GUI one button should be shown as "POWER ON" for this system and if ON is present one button is shown as "POWER OFF".

      Below is the cgi file:

      #!/usr/bin/perl use strict; #use CGI qw/:standard/; #use CGI qw( :html *p); use CGI qw(:cgi-lib :standard); &ReadParse(*input); use CGI qw( :html *p); use CGI::Pretty; print header, start_html('Utilization'); my $cgi_obj = new CGI(); my $power_on = $cgi_obj->param('power_on'); my $power_off = $cgi_obj->param('power_off'); if($power_off){ Change::change_file("INFO", "$power_off", "POWER_STATUS", "OFF"); } if($power_on){ Change::change_file("INFO", "$power_on", "POWER_STATUS", "ON"); } my $h = "<h3><font color=\"#0B0B61\"><center><b>System Management Page +</b></center></font color> </h3>"; $h .= "<table border=\"1\">\n<tr>\n";</p> $h .= "<td WIDTH=50 bgcolor=\"#0101DF\"><font color=\"#FFFFFF\ +"><strong><center>Serial No.</center></strong></td>\n"; $h .= "<td WIDTH=200 bgcolor=\"#0101DF\"><font color=\"#FFFFFF +\"><strong><center>NAME</center></strong></td>\n"; $h .= "<td WIDTH=200 bgcolor=\"#0101DF\"><font color=\"#FFFFFF +\"><strong><center>IP</center></strong></td>\n"; $h .= "<td WIDTH=200 bgcolor=\"#0101DF\"><font color=\"#FFFFFF +\"><strong><center>State_ON_OFF</center></strong></td>\n"; $h .= "<td WIDTH=200 bgcolor=\"#0101DF\"><font color=\"#FFFFFF +\"><strong><center>Used state</center></strong></td>\n"; $h .= "</tr>"; <p>open(my $FH,"INFO") or die ("$!");</p> <p> my $ref={};</p> <p>my $i = 1;</p> <p> while(<$FH>){</p> <p>my ($NAME,$IP,$POWER_OFF_ON,$USED_STATE)=split(/,/);</p> $h .= "<tr>"; $h .= "<td WIDTH=50 bgcolor=\"#BCF5A9\"><center>$i.</center></ +td>"; $h .= "<td WIDTH=150 bgcolor=\"#BCF5A9\"><center>$NAME</center +></td>"; $h .= "<td WIDTH=150 bgcolor=\"#BCF5A9\"><center>$IP</center>< +/td>"; if ( $POWER_OFF_ON eq "OFF"){ $h .= "<form name=\"ON\" method=\"get\" action=\"tool. +cgi\"><br>"; $h .= "<td WIDTH=250 bgcolor=\"#BCF5A9\"><center>$POWE +R_OFF_ON<br>"; $h .= "<input type=\"hidden\" name=\"power_off\" value= +\"$NAME\">"; $h .= "<center><input type=\"submit\" value=\"SWITCH ON +\"></center</td>"; $h .= "</form>"; } else { $h .= "<form name=\"OFF\" method=\"get\" action=\"tool. +cgi\"><br>"; $h .= "<td WIDTH=250 bgcolor=\"#BCF5A9\"><center>$POWER +_OFF_ON<br>"; $h .= "<input type=\"hidden\" name=\"power_ +off\" value=\"$NAME\">"; $h .= "<center><input type=\"submit\" value=\"SWITCH OF +F\"></center</td>"; $h .= "</form>"; } $h .= "<td WIDTH=150 bgcolor=\"#BCF5A9\"><center>$USED_STATE</ +center></td>"; $h .= "</tr>"; $i++; } print "$h"; print $cgi_obj->end_html(); exit;

      I want that if "POWER ON" button is pressed. It changes the INFO file and corresponding to that system it replaces OFF ny ON and the display the same cgi file with update data. Now as written in line 15 and line 18. one subroutine called change_file is called if "POWER ON" or "POWER OFF" buttons are pressed which changes the value as asked.

      Subroutine from the Change.pl

      my ($name, $selected_system, $value_to_change, $new_val) = @_; my $ref; my ($NAME,$IP,$POWER_OFF_ON,$USED_STATE); rename $name, "$name~" or die "Cannot rename: $!"; open FH1, "<$name~" or die "Cannot open: $!"; open FH2, ">$name" or die "Cannot create: $!"; while (<FH1>) { ($NAME,$IP,$POWER_OFF_ON,$USED_STATE)=split(/;/); $ref->{$NAME}{FILER_IP}=$FILER_IP; $ref->{$NAME}{FILER_RLM_IP}=$FILER_RLM_IP; $ref->{$NAME}{POWER_OFF_ON}=$POWER_OFF_ON; $ref->{$NAME}{OWNER}=$OWNER; $ref->{$NAME}{DETAILS}=$DETAILS; $ref->{$NAME}{RESERVED_BY}=$RESERVED_BY; print "$NAME",";","$ref->{$NAME}{FILER_IP}",";","$ref->{$NAM +E}{FILER_RLM_IP}",";","$ref->{$NAME}{POWER_OFF_ON}",";","$ref->{$NAME +}{OWNER}",";","$ref->{$FILER_NAME}{DETAILS}",";","$ref->{$FILER_NAME} +{RESERVED_BY}"; print "$NAME",";","$ref->{$NAME}{FILER_IP}",";","$ref->{$NAME +}{FILER_RLM_IP}",";","$ref->{$NAME}{POWER_OFF_ON}",";","$ref->{$NAME} +{OWNER}",";","$ref->{$FILER_NAME}{DETAILS}",";","$ref->{$FILER_NAME}{ +RESERVED_BY}"; if (!($NAME eq "$selected_system")){ print FH2 $_; } elsif ($value_to_change eq "POWER_STATUS"){ print FH2 "$NAME",",","$ref->{$NAME}{IP}",",","$new_val","," +,"$ref->{$NAME}{USED_STATE}","\n"; } }

        &ReadParse(*input);??? You should never use that

Re: To call a .pl file when a button is pressed on a GUI created using Perl CGI
by Anonymous Monk on Sep 25, 2013 at 01:20 UTC

      Thanks for the reply. I will definitely go through the links you have send.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1055479]
Approved by Corion
help
Chatterbox?
[Corion]: marioroy: Oh, that's always cool, having API-compatible modules. This makes testing and comparing things much easier
[marioroy]: IPC in MCE::Shared can handle 400k (sends) per second. That's seems a lot for being a pure-Perl module. After making the release, will come back and post a solution for a node by a fellow wanting faster logging.
[Corion]: While working on WWW::Mechanize:: Chrome, I had the suspicion that AnyEvent was doing something wrong, but I was able to swap it out for Mojolicious and the error persisted.
[Corion]: Of course, the error was in my own code ;)
[marioroy]: Corion, start and start_child in MCE::Hobo::Manager return a MCE::Hobo object, whereas P::FM returns the PID. I can have it return the PID though. I tried Hobo::Manager with several P::FM modules, just changed P::FM to MCE::Hobo::Manager and it works.
[marioroy]: I also have a Hobo driver for Forklift allowing folks to use in multiple classes, no conflicts with one another. That's not possible for P::FM.
[Discipulus]: congrats marioroy!
[marioroy]: CORE::wait works well eventhough multiple instances or classes using Hobo::Manager.
[Corion]: marioroy: I'm not sure what the normal use for the PID is in P:FM, but I guess that most programs just ignore or log it

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2017-05-26 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?