Janish has asked for the wisdom of the Perl Monks concerning the following question:
I have spent my time for the past weeks to read through the materials available on web, and below is the code that I comes out, applying Tk::ExecuteCommand module. From my end, I'm able to execute the command successfully if I keyed-in a single liner command within the entry created from the module. However in real case, I'll need to perform a series of tasks within a subroutine, which in my case I would like the button click to perform the jobs defined in my subroutine with the result displayed on the window. Pls help me on this.
Below is my code but it is fail to call the subroutine to perform, can someone point me where are my errors. Thank you.
#!/usr/bin/perl use Tk; use Tk::ExecuteCommand; my $mw = MainWindow->new; my $param1 = "word1" ; my $param2 = "word2" ; #my $cmd = `&test($param1, $param2)` ;#Subroutine to be called by the +Tk::ExecuteCommand button click my $cmd = sub { my $commandline= "/nfs/work/testing123.pl -text text"; system($commandline) == 0 or warn "Couldn't launch [$commandline]: $!/$?"; #system ("/nfs/work/testing123.pl -text text" &") ; }; $ec = $mw->ExecuteCommand( -command => '', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute', )->pack; $ec->configure(-command => $cmd); $ec->update; MainLoop; sub test {#Subroutine that create a text file to be used in later exte +rnal Perl script. my ($param1, $param2) = @_ ; my $param1_val = $param1->get ; my $param2_val = $param2->get ; open (TEXT, ">text") ; print TEXT "Field1: $param1\n" ; print TEXT "Field2: $param2\n" ; close TEXT ; open (PROJ, '-|', 'perl /nfs/work/testing123.pl -text text') or di +e "unable to start $!"; my $first_line = "Start program...please wait"; $ec->insert( 'end', $first_line ); my $proj_line; while (defined ($proj_line =<PROJ>) ){ $ec->insert( 'end', $proj_line ); $ec->update(); } } ---end-----
|
|---|