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

A few months ago, I found out (from here) that one could say:
system 1,"some junky windows command";
and windows would "execute" it in the background. Now I've found out that "not quite". It seems that it gets scheduled, and doesn't start until your current program (the perl script) is done. This is mostly OK, but I want to establish a socket connection to the program, and it isn't there until I do something. My question: how do I pause my program (perl script) and let the other thing (a gui goodie I can control) take off. It seems that this varies between W2K and WXP, or other variables.

I've tried "sleep...", and a "poll..." to no avail. Does anyone have suggestions. Thanks.

Also: where is the 1, part of the system command used on windows described. A pointer??

Replies are listed 'Best First'.
Re: Async on windows (again)
by ikegami (Patriarch) on Jul 27, 2006 at 03:16 UTC

    It seems that it gets scheduled, and doesn't start until your current program (the perl script) is done.

    It should start immediately, and it does so in my experience. In the following program, you can see that the parent and the child are executing concurrently.

    #!perl -l system 1, q/perl -le "print 'child'; sleep 2; print 'child'"/; sleep 1; print 'parent'; sleep 2; print 'parent';

    outputs

    child parent child parent

    Also: where is the 1, part of the system command used on windows described. A pointer??

    perlport. Search for system(1, @args).

Re: Async on windows (again)
by gellyfish (Monsignor) on Jul 27, 2006 at 08:34 UTC

    where is the 1, part of the system command used on windows described.

    I think this should be considered an "undocumented feature" and I'm not sure you should rely on it. If you want more control you probably want to look at the windows CreateProcess API or Win32::Process.

    ?J\