logo
down
shadow

Running an external command in Perl / Tkx without blocking the GUI (Windows)


Running an external command in Perl / Tkx without blocking the GUI (Windows)

By : Richard Van Parys
Date : November 19 2020, 03:59 PM
Any of those help After spending almost 2 days on the problem I have finally found out the answer thanks to a post here with a code for Tcl that I adapted to Tkx.
The solution is to use Tkx::open (in combination with its cousins "read" and "close").
code :
use Tkx;
use strict;
use Data::Dumper;

my ($stdout,$stderr);

my $mw = Tkx::widget->new(".");
my $button=$mw->new_ttk__button(-text => "Run", -command => [\&run_command, "systeminfo"]);
$button->g_grid(-column => 0, -row => 0);
my $text = $mw->new_tk__text(-width => 32, -height => 16);
$text->insert("end", "Test\n");
$text->g_grid(-column => 0, -row => 1);

Tkx::MainLoop();
print "STDOUT: $stdout\n\n","-"x24,"\nSTDERR: $stderr\n";


sub run_command {
    my $cmd = shift;
    my $fh = Tkx::open("| $cmd", 'r') or die "$!";
    Tkx::fconfigure($fh, -blocking => 0);
    $stdout.=Tkx::read($fh);
    eval { Tkx::close($fh); };
    $stderr.=$@ if ($@);

}


Share : facebook icon twitter icon
How can I execute an external Windows command and instantly return in Perl?

How can I execute an external Windows command and instantly return in Perl?


By : Yeari
Date : March 29 2020, 07:55 AM
I wish this help you I've tried using system() with fork(), tried exec(), and am still not getting what I need. , On Windows, you can give the super-secret 1 flag to the system, IIRC.
code :
system 1, @cmd;
NoClassDefFoundError when running Java from Windows command line with external jar files

NoClassDefFoundError when running Java from Windows command line with external jar files


By : user34140
Date : March 29 2020, 07:55 AM
I wish this help you You need to put the jars as a parameter to java as well, same as you passed for javac.
Error stream blocking when running external command with Java

Error stream blocking when running external command with Java


By : Colin freeman
Date : March 29 2020, 07:55 AM
wish help you to fix your issue First, it's probably better to use the newer ProcessBuilder class as opposed to Runtime exec. If you want to go a step further, you can even use Apache commons-exec which takes care of stream handling and other things for you.
Next, as you've discovered, process control is a tricky thing in Java and you've run into one of its tricky issues. From the documentation for java's Process class:
How Windows cmd transforms the command line when running Perl one-liners?

How Windows cmd transforms the command line when running Perl one-liners?


By : Joey Zhao
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Who cares? The exact rules are convoluted and hard to remember. Just avoid the problem by not using double quotes in your Perl one liners. You know you have ', q{} and qq{} available.
Perl Scripting: Running mv as external command

Perl Scripting: Running mv as external command


By : BigBubba65
Date : March 29 2020, 07:55 AM
wish helps you Here's a script that reproduces something very similar to the error messages you're seeing:
Related Posts Related Posts :
  • Perl script does not recognize paths which contains environment variables
  • How to stop Runaway Perl Process
  • Scoping variables in a Perl Test::More .t file
  • Perl Sort Array
  • Content-Type setting for .MTS files
  • Seek function not working in perl
  • Perl syntax error printing list index
  • perl matching syntax with mail filter
  • Error Handling Using Perl Tkx
  • Perl : calculation of time in format hh:mm:ss,sss
  • Remove element from array containing empty or whitespace character in Perl
  • Passing multiple values to a Perl program in a single command line argument
  • perl Parallel::ForkManager stuck in this script?
  • Unable to escape @ sign in perl
  • Loop to define buttons in Perl / Tkx
  • Why can't the Opsview_rest Perl script not find the OPSVIEW_URL_PREFIX Environment variable using $ENV{var} while it has
  • Get http-response header with Perl's File::Fetch
  • Perl Get the web content then writing it as a text file
  • perl $CGI::POST_MAX all parameters
  • Perl Foreach until loop
  • login failed to remote host - prompt does not match at /usr/lib/perl5/site_perl/5.10.0/Net/Appliance/Session/Transport.p
  • How is a literal list having one element represented unambiguously in perl?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org