1

I tried to achieve above using the snippet from CPAN Tk::ExecuteCommand module but it gives me errors below when I execute any Perl program within the $ec->configure(-command section.

Also, the window will be closed unexpectedly once the Perl job completed. The script works and will not be closed if I just print the text instead of command within the entry (as the line I commented out). I choose to use this Cpan program as I wanted 2 things:

  1. To show the system command and run result within the text widget.
  2. To have the "execute button" turn to "cancel" when a job is running so that user could have chances to cancel an ongoing job.
    May I know how to achieve that?

Here is the error msg I get:

 > /usr/bin/perl: symbol lookup error: /usr/pkgs/perl/5.14.1/lib64/module/default/x86_64-linux/auto/Proc/ProcessTable/ProcessTable.so: undefined symbol: pthread_once

[13] Exit 127 test1.pl

And here is the code I used:

#!/usr/bin/perl

use Tk;
use Tk::ExecuteCommand;

$ec = tkinit()->ExecuteCommand(
     -command    => '',
     -entryWidth => 50,
     -height     => 10,
     -label      => '',
     -text       => 'Execute',
)->pack;
$ec->configure(-command => 'perl ./my_script.pl -wrapper wrapper_txt');
#$ec->configure(-command => 'Text line only');
$ec->execute_command;
$ec->update;

MainLoop;
halfer
  • 19,824
  • 17
  • 99
  • 186
Grace
  • 440
  • 3
  • 6
  • 21

1 Answers1

2

Change $ec->configure(-command => 'perl ./my_script.pl -wrapper wrapper_txt'); to $ec->configure(-command => 'perl my_script.pl -wrapper wrapper_txt');

and to get the status use a sub like below

sub sys {

    # Execute a command asynchronously and return its status and output.

    my $cmd = shift;

    $ec->configure( -command => $cmd );
    my $t = $ec->Subwidget( 'text' ); # ROText widget
    $t->delete( '1.0' => 'end' );
    $ec->execute_command;
    return ($ec->get_status)[0], split /\n/, $t->get( '1.0' => 'end -1 chars' );

} # end sys

For killing it using a button, check the documentation, it says

This ExecuteCommand mega widget is composed of an LabEntry widget for command entry, a "Do It" Button that initiates command execution, and a ROText widget that collects command execution output. While the command is executing, the "Do It" Button changes to a "Cancel" Button that can prematurely kill the executing command. The kill_command method does the same thing programmatically.

So you need $exec->execute_command; $exec->get_status; and $exec->kill_command;.

Edit: Looks like a known issue, try using latest version of Proc::ProcessTable.

Also see: Bug #41397 for Proc-ProcessTable: Proc::ProcessTable - make test fails "undefined symbol: pthread_once"

Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133
  • hi Chankey, Thanks for your reply. WIth the code I posted above, they actually works but it abort once the perl command run complete ( I saw the result prompt within the text widget, but the window closed immediately after that). At the Unix prompt which I invoked the script, it shows error " symbol lookup error: /usr/pkgs/perl/5.14.1/lib64/module/default/x86_64-linux/auto/Proc/ProcessTable/ProcessTable.so: undefined symbol: pthread_once". The suggested solution seems not works for me :(. – Grace Jun 20 '14 at 04:14
  • Then it looks like some libraries are missing. Are you using latest version of `Proc::ProcessTable`? See this: http://blogs.perl.org/users/gabor_szabo/2012/09/procprocesstable-needs-a-c-lover.html – Chankey Pathak Jun 20 '14 at 04:22
  • I'm actually not sure how to check that and I suppose that should be included when I called the "use Tk::ExecuteCommand" right?. My Perl version is v5.14.1. – Grace Jun 20 '14 at 04:25
  • `perl -MProc::ProcessTable -e 'print $MODULE::VERSION';` The latest version is 0.50 https://metacpan.org/pod/Proc::ProcessTable – Chankey Pathak Jun 20 '14 at 04:33
  • I have included "use Proc::ProcessTable;" but seems still complaining same error. Could you explain what is this error means? Wonder if above codes works at your end? – Grace Jun 20 '14 at 04:46
  • You don't have to include Proc::ProcessTable. Just check the version of it using the above command I wrote. There were many bugs in 0.45 version of module, I suspect you are using that version. Check it. `perl -MProc::ProcessTable -e 'print $MODULE::VERSION';` – Chankey Pathak Jun 20 '14 at 04:54
  • I failed to check the version with either of these:- (i)system ("perl -MProc::ProcessTable -e 'print $MODULE::VERSION'") ; (ii) `perl -MProc::ProcessTable -e 'print $MODULE::VERSION';` ; – Grace Jun 20 '14 at 05:01
  • do `cpan Proc::ProcessTable` from your shell. – Chankey Pathak Jun 20 '14 at 05:15
  • Like this? > cpan Proc::ProcessTable CPAN: File::HomeDir loaded ok (v0.66) – Grace Jun 20 '14 at 05:24
  • `[root@host]# cpan Proc::ProcessTable`. Screenshot: http://i.imgur.com/dEDVHPU.jpg – Chankey Pathak Jun 20 '14 at 05:31
  • The only I get is : > cpan Proc::ProcessTable CPAN: File::HomeDir loaded ok (v0.66) CPAN: Storable loaded ok (v2.18) CPAN: LWP::UserAgent loaded ok (v5.816) CPAN: Time::HiRes loaded ok (v1.9711) – Grace Jun 20 '14 at 05:44
  • What's the output of this: `perldoc -l Proc::ProcessTable` – Chankey Pathak Jun 20 '14 at 05:48
  • > perldoc -l Proc::ProcessTable /usr/pkgs/perl/5.14.1/lib64/module/r1/x86_64-linux/Proc/ProcessTable.pm – Grace Jun 20 '14 at 06:00
  • It's installed then. Try running your script again, do you get same error? – Chankey Pathak Jun 20 '14 at 06:02
  • See the edited answer, it's a bug. In the link you'll find the patch to solve this. – Chankey Pathak Jun 20 '14 at 06:04
  • Could you pls pin point me the error? I could spot where is it within the link. And the http://www.cpan.org/authors/id/SREZIC/patches/Proc-ProcessTable-0.45-MSCHILLI-02.patch is unaccessible to me though. – Grace Jun 20 '14 at 06:12
  • Download the module from here: https://metacpan.org/pod/Proc::ProcessTable and install it manually. Link to patch for 0.45 version is: http://www.cpan.org/modules/by-module/Geo/SREZIC/patches/Proc-ProcessTable-0.45-MSCHILLI-02.patch – Chankey Pathak Jun 20 '14 at 06:15
  • I have downloaded and untar, may I know how to apply it on my script? Can you give me a sample? Thanks in advanced. – Grace Jun 20 '14 at 06:30
  • I declared as below, yet still getting same error msg:- use Tk; use Tk::ExecuteCommand; use lib '/nfs/fm/grace_work/Proc-ProcessTable-0.50' ; – Grace Jun 20 '14 at 06:42
  • Then I guess the bug is not solved in 0.50 also. Can't do anything about it. – Chankey Pathak Jun 20 '14 at 06:45
  • DO you have alternative solution to achieve that beside using this cpan method? – Grace Jun 20 '14 at 06:49
  • Hi Pathak, I'm finally able to apply the execute cpan module by changing my perl shebang to newer version. Thanks for the hint. I actually still not able to achieve my goal as my codes reading from wrapper instead of a command line. I'm wondering if I can really apply this execute command module. I'm going to create a new question on this forum. Pls see if you could help me on that too. Thanks! – Grace Jun 25 '14 at 03:25