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

I have to prepare a GUI , where the Perl/Tk should invoke a batch command (a local one with path hardcoded) and passing argument (which is the .csv file selected by the user) -When user presses the GENERATE button-here simplified as just opening the .csv file in notepad . Can someone help me ?

use Tk; my $my_MW=MainWindow->new(); $my_MW->title("Sample application"); $my_MW->geometry("350x180-500+500"); $my_MW->resizable( 'no', 'no' ); my $my_Button=$my_MW->Button(-text=>"Select CSV Input File",-command=> + \&get_file); $my_Button->pack(-side=>"top",-expand=>1,-anchor=>"w",-padx => 20,-pad +y => 20); my $filepath=" .... "; my $my_Entry=$my_MW->Entry(-textvariable=> \$filepath); $my_Entry->pack(-side=>"top",-expand=>1,-anchor=>"w",-padx => 20,-pady + => 0,-fill=>"x"); my $my_Button1=$my_MW->Button(-text=>"GENERATE",-width => 12,-command= +>sub{\&gen_rslt()}); $my_Button1->pack(-side=>"left",-expand=>1,,-pady => 20); $my_Button1->configure(-state => 'disabled'); my $my_Button2=$my_MW->Button(-text=>"RESET",-width => 12,-command=>su +b{\&clear_field()}); $my_Button2->pack(-side=>"left",-expand=>1,,-pady => 20); my $my_Button3=$my_MW->Button(-text=>"EXIT",-width => 12,-command=>sub +{exit()}); $my_Button3->pack(-side=>"left",-expand=>1,,-pady => 20); MainLoop(); sub gen_rslt{ #Call the batch file and pass the file path as an argument! #batch file to open the file in notepad } sub clear_field{ $my_Entry->delete(0,'end'); $my_Entry->insert(0," .... "); $my_Button1->configure(-state => 'disabled'); } sub get_file { $my_Entry->delete(0,'end'); my @types = (["comma seperated files", [qw/.csv/]], ["All files", '*'], ); $filepath = $my_MW->getOpenFile(-filetypes => \@types) or return(); $my_Button1->configure(-state => 'normal'); }

Replies are listed 'Best First'.
Re: Perl/Tk invoking a batch command and passing argument
by Anonymous Monk on Jan 26, 2016 at 07:46 UTC
Re: Perl/Tk invoking a batch command and passing argument
by u65 (Chaplain) on Jan 26, 2016 at 11:45 UTC

    And of course you should have

    use strict; use warnings;

    at the top of your code.