dbleonard has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I am using a system call: system "wgnuplot.exe -persist $plotstring"; within a large perlTK program under ActiveState 5.8.8. The plot works perfectly, however, upon closing the plot, the main program freezes and looses all functionality. All of the top levels become white and imobile. This does not seem to happen from a simple script style perl program. I have tried backticks, system, a system call within an eval, and an exec. The exec works but kills the main program. I also tried running the system call as a thread and then detaching it. None of these worked. I would greatly appreciate any suggestions. Thanks!

Replies are listed 'Best First'.
Re: perlTK system calls in Windows
by eserte (Deacon) on Dec 19, 2006 at 09:31 UTC
    What about the special system() form with a preceding 1:

    system(1, @cmdline)

    (See perldoc perlport for more information)

Re: perlTK system calls in Windows
by rinceWind (Monsignor) on Dec 19, 2006 at 11:04 UTC

    As eserte says, using system with a first parameter of 1 is a way of background launching a task, when you are not interested in capturing the output. The reason why your GUI is freezing up is that the program was servicing the system request, not returning into the Tk event loop, so as not to be able to service any GUI events. If you have this problem inside perl code, you can alleviate the problem by periodically calling $main_window->update - a handy trick when using the debugger on a Tk application.

    For the times when you are interested in capturing output, use a piped open, open2 or open3, and Tk::fileevent to set up a callback that can read the captured output, line by line.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

Re: perlTK system calls in Windows
by zentara (Cardinal) on Dec 19, 2006 at 13:36 UTC
    In addition to what has already been mentioned, on linux, we would say you need a "fork-and-exec", not just simply and exec. By the way, the '-persist' option to gnuplot may be the culprit, it keeps the subprocess alive which drives the display.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum