Hi monks,

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-----

In reply to How to perform a subroutine run in cpan Tk::ExecuteCommand module by Janish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.