Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

'system' hangs in a Windows Tk app

by ff (Hermit)
on Mar 27, 2006 at 20:55 UTC ( #539540=perlquestion: print w/replies, xml ) Need Help??
ff has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I hope this is not too esoteric, but I'm having a problem with system on my W2K machine after upgrading from ActiveState Perl 5.8.4 to 5.8.8. Things like the following initiate action, such as running vim against a specified file, but then control does not seem to return to my program, i.e. the Tk window from which I kicked off the system command has frozen and I have to kill the application.

$mw->iconify(); $found_problem = system $path_of_wp, $abs_pgm_log_file; $mw->deiconify();

In the Release Notes section of the 5.8.8 documentation there is a section called 'New warnings and deprecations'. Among other things it says that:

The exec LIST and system LIST operations now produce warnings on tainted data and in some future release they will produce fatal errors.

I'm not running the program in Taint mode and so I wouldn't expect this is relevant. But maybe it is.

Elsewhere in the docs, I find the following, though this should have been absorbed/okay on my previous platform of 5.8.4.

Build 808 Saturday, Dec 6, 2003
Build 808 is based on Perl 5.8.2.


Build 805 Thursday, Feb 6, 2003
Bug Fixes and Changes

On Windows, system() and backticks could return invalid status when running under environments where the process has to handle Windows messages. PerlScript and Perl for ISAPI fall under this category. The problem has been corrected.

The following seems to illustrate the problem on my (now) 5.8.8 system; running it produces a widget with an 'Ok' button; press it, you edit a README file, but the controlling Tk app in the background does not experience a destroy. Switch to the dummy line instead of the system line and it seems to destroy just fine. Hmm.


use Tk; use strict; my $poss_answer = 'Ok'; my $answer = 'Ok'; my $mw = MainWindow->new; $mw->Radiobutton( -text => $poss_answer, -value => $poss_answer, -variable => \$answer, -padx => 10, -command => sub { warn "TkAns82: '$answer'\n"; my ( $path_of_wp, $abs_pgm_log_file ) = ( 'C:\vim\vim61\gvim.exe', 'C:\vim\vim61\README.txt', ); $mw->iconify(); my $found_problem = system $path_of_wp, $abs_pgm_log_file; #= 'dummy'; $mw->deiconify(); $mw->destroy(); }, )->pack( -side => 'bottom', ); $mw->withdraw; #avoid the jumping window bug $mw->Popup; MainLoop();

Replies are listed 'Best First'.
Re: 'system' hangs in a Windows Tk app
by swampyankee (Parson) on Mar 27, 2006 at 21:01 UTC

    I saw the same thing with a Perl/Tk application when I upgraded to ActiveState's 5.8.8. The code was working in 5.8.7, but would hang in 5.8.8. I reverted to 5.8.7 (I don't have the time to go chasing bugs in other people's code.)

    Time for a bug report, perhaps?


    " The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents."
    —Nathaniel S. Borenstein
      Thanks, swampyankee. I'm a little gunshy about declaring something as a bug and it's nice to get corroboration before submitting a report. I did so (my bug) and ActiveState said it was similar to a bug reported six days ago. (previous bug)

        I submitted mine (which was also categorized as a duplicate of the same bug.

        Now, to see how long it takes them to fix it……


        " The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents."
        —Nathaniel S. Borenstein
Re: 'system' hangs in a Windows Tk app
by Courage (Parson) on Mar 28, 2006 at 07:15 UTC
    I happen to do almost exactly what you ask - I place a button on Tk and when user presses it, I invoke VIM.

    In order to achieve this, you need

    Win32::Process::Create($pobj, "$args[0]", "@args", 0, NORMAL_PRIORITY_CLASS, ".") || die "can't Win32::Process::Create: (\@args=[@args])". Win32::F +ormatMessage(Win32::GetLastError());
    See proper documentation.

    Also, using Tcl::Tk as a replacement to perlTk will give you many advantages.

    Best regards,
    Courage, the Cowardly Dog

      Thanks, Courage. Several other notes seem to pity users of system but they don't say what to do about it. I tried your method and my process does not get hung. There appear to be many interesting controls for Win32::Process and I will examine some other places in my code where I'm not satisfied with how system behaves.

      In this particular case, I have opened a bug report and find that my problem is similar to another recently submitted bug and ActiveState is working on it. (?)

      As for an alternative to Tk, people have said that my interface looks old-fashioned, 80's-ish, etc., and I wouldn't mind an alternative, but I'm pretty invested and will need to gain traction with my app before I can afford to make any big changes. :-)

        Tk could be considered old-fashioned, but:
        • its Text and Canvas are very powerful, and this could outweight many drawbacks
        • Tk has Tile, see how it could be used
        • I did not adviced you to switch from Tk to an alternative, I just adviced to use Tk differently and more effectively.

        On another point, if "old-fashioned" Tk is denied by end-users of software, you can actually use *any* GUI toolkit from Perl.
        I, for one, started from using Perl from within C++Builder GUI, but then, step by step, I switched to something more powerful.

Re: 'system' hangs in a Windows Tk app
by zentara (Archbishop) on Mar 27, 2006 at 21:27 UTC
    I don't use Windows, and I have a hard time understanding why you want to deiconify the $mw just to destroy it. Your script destroys the $mw fine on linux, with Perl 5.8.8 and the latest Tk. I am not sure why, but I have noticed in the past, that $mw->deiconify() often needs to be used in conjunction with $mw->raise.

    On linux, if I comment out your $mw->destroy(), to see if control returns after the system, the $mw will NOT deiconify, and the system command just seems to hang ( which is the problem you are seeing? ).

    But, if I put a raise after the deiconify, control returns.

    $mw->deiconify; $mw->raise
    So try adding a $mw->raise and see if it helps.

    I'm not really a human, but I play one on earth. flash japh
      Sorry, deiconify seems to be a bit of misdirection there. My deiconify snippet here comes from another statement block that also experiences the system problem. The actual system command I do there in that Radiobutton part is more complicated, but the outside behavior of "hanging" after doing the command is the same. Yes, later in my code I see that I use $mw->raise() and there is no destroy in sight.
Re: 'system' hangs in a Windows Tk app
by Anonymous Monk on Mar 28, 2006 at 13:08 UTC
    ActivePerl- has a bug, downgrade or wait for ActivePerl-
Re: 'system' hangs in a Windows Tk app
by Anonymous Monk on Mar 30, 2006 at 13:49 UTC
    ActiveState has released ActivePerl 03/29/2006 It fixes a number of serious issues that have been found in the 816 release: * Restored binary compatibility to previous releases. * Fixed several bugs on Windows related to GUI applications and signal handling. These bugs were introduced in build 816. * Updated threads and threads::shared modules to fix resource leaks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://539540]
Approved by Corion
Front-paged by Courage
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2018-07-21 11:10 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (448 votes). Check out past polls.