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

This is probably pretty simple, but... I desire to start another process from a Win32 perl script. If I were in unix, I'd just write
system "ls -l 2>Xerr >Xout &";
And go from there. Well, I'm in (Yuck!) Win32 and that doesn't work, thus the question. Oh, yes I'd like the sub process to get specific file descriptors that I specify like the example above. This may be the hard part. Eventually I'll wait for the process to end, and that may be another call. Yes, I'm using XP/2000/NT (not 95/98/Me), because they are the ones that can have tasks like this.

Update...... Well, I tried:

system 1, "program 2>Xerr >Xout";
and that works, BUT... Windows desires to put up an empty command window (yuck!) and there is a rare instance where I might want to abort 'program'. What to do now? Also, where is the "system 1," thing documented? I also tried the "start /b" goodie, but it put up a command window as well. The information so far will allow me to do my deeds, but (as usual) I need a bit more (*SIGH*).

Replies are listed 'Best First'.
Re: Async execution in Win32
by ikegami (Patriarch) on Mar 15, 2006 at 01:21 UTC
    system "start program 2>Xerr >Xout";

    Update: Doh! In the above, the redirections apply to start, but not to program. Here is something that works (tested):

    system 1, 'program 2>Xerr >Xout';

      Your start version seems to work for me?

      [0] Perl> system q[cmd /c del errors output];; [0] Perl> system q[start /b perl -le"print for 1..10; die 'An error';" + 2>errors 1>output];; [0] Perl> system q[cmd /c type errors output];; errors An error at -e line 1. output 1 2 3 4 5 6 7 8 9 10

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        You added "/b". That made a difference.
Re: Async execution in Win32
by adamk (Chaplain) on Mar 15, 2006 at 10:29 UTC
    I know you have your answer, but if the async stuff is a Perl program, you might also be interested in the Process:: family of modules, specifically Process::Backgroundable in this case.