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

I'm now using IPC::Open2 along with perl tk on Windows, to allow the program to call a child program to do some background work and prevent locking up the Tk GUI. The problem I have though is that the IPC::Open2 code doesn't seem to work unless there is a DOS window. I found this code in the "perl cookbook" to remove the DOS window when using perl/Tk, but it can't work along with IPC::Open2:
#!/usr/bin/perl -w # loader - starts Perl scripts without the annoying DOS window use strict; use Win32; use Win32::Process; # Create the process object. Win32::Process::Create($Win32::Process::Create::ProcessObj, 'D:/perl/bin/perl.exe', # Whereabouts of Perl 'perl c:/f1.pl', # 0, # Don't inherit. DETACHED_PROCESS, # ".") or # current dir. die print_error(); sub print_error() { return Win32::FormatMessage( Win32::GetLastError() ); }
Does anyone have any idea how I might make this work? Maybe using some other piping or socket type operations? I am on Windows, though, so the perl there doesn't yet fully support fork when you use other thread unsafe modules. I've found that out the hard way several times. Thanks for any info!!!

Justin Eltoft

"If at all god's gaze upon us falls, its with a mischievous grin, look at him" -- Dave Matthews

Replies are listed 'Best First'.
Re: IPC::Open2, Tk, and DOS window
by jlongino (Parson) on Oct 03, 2001 at 20:22 UTC
      Thanks, but I'm already able to do this easily with the aforementioned code, and BTW I'm using Tk, not win32::gui. I appreciate the reply though.

      Maybe I should clarify some more. I'm able to remove the console DOS window with this above code, but when you do that it appears to wreak havoc with the IPC::Open2 function that wants to communicate to the child process on the child process's STDIN. I assume this is because removing the DOS console removes the connnection to both STDIN and STDOUT of the parent. What really confuses me though is that I'm not really trying to use STDOUT on the parent. I thought I was just using a filehandle and only the child process has to have STDIN.

      Justin Eltoft

      "If at all god's gaze upon us falls, its with a mischievous grin, look at him" -- Dave Matthews

        Re-reading my post I realize the intent wasn't phrased clearly. The referenced link showed alternate ways to run perl programs without a DOS console, not necessarily just those using Win32::Gui, but Tk as well. Unfortunately, all the methods described likely have the same problem with STDIN/STDOUT.

        "Make everything as simple as possible, but not simpler." -- Albert Einstein

        IPC::Open2 always has the child's STDERR go to the parent's STDERR. This may cause problems if the parent no longer has a STDERR.

        I'd try using IPC::Open3 and be sure to specify alternates for all three. Note that having the child's STDOUT and STDERR go to separate pipes can lead to deadlock so either send them both to the same pipe or send one or both of them to a file or even:

        open(NUL,">nul") or die "nul: $!"; open3( ...., \*NUL, ... )
        [ BTW, I think IPC::Open3 should be patched to handle     open3( "<nul", ">out.txt", ">err.txt", ... ) (: ]

                - tye (but my friends call me "Tye")