Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

How does system(1,"foo") work on Windows?

by McMahon (Chaplain)
on May 03, 2006 at 16:43 UTC ( #547206=perlquestion: print w/ replies, xml ) Need Help??
McMahon has asked for the wisdom of the Perl Monks concerning the following question:

Windows has no fork(). Various languages have implemented threads on Windows with varying degrees of success.

But Perl is the only language I've come across that has anything like system(1,"blah") that returns control to the calling Perl script on Windows. It doesn't seem like it would be possible, but it works flawlessly as far as I can tell.

I find myself writing and running scripts in a number of languages, but whenever I need a controller for more than one script, regardless of language, I turn to Perl because of system(1,"xyz").

When people ask me how it works, though, I have to just say "magic". I've recently started using it again in some controller scripts, and now I feel like I should find out what's really going on.

So -- how does system(1,"foo") work on Windows?

Comment on How does system(1,"foo") work on Windows?
Re: How does system(1,"foo") work on Windows?
by derby (Abbot) on May 03, 2006 at 16:55 UTC
      Fascinating:

      Support for concurrent interpreters and the fork() emulation was implemented by ActiveState, with funding from Microsoft Corporation.

      -sam

      I think the more specific link should be perlport (and then scroll down to "system"). This notes that system(1, @args) does the magic thing, and also that it's Win32 specific (which is a bit of a shame).

      --
      .sig : File not found.

Re: How does system(1,"foo") work on Windows?
by Anonymous Monk on May 03, 2006 at 17:13 UTC
    Didn't you answer this already? magic!
Re: How does system(1,"foo") work on Windows?
by ikegami (Pope) on May 03, 2006 at 17:19 UTC
    But Perl is the only language I've come across that has anything like system(1,"blah") that returns control to the calling Perl script on Windows.

    The system call CreateProcess can achieve this. CreateProcess can be called from C, C++, Perl and surely many other languages.

Re: How does system(1,"foo") work on Windows?
by BrowserUk (Pope) on May 03, 2006 at 17:26 UTC
    So -- how does system(1,"foo") work on Windows?

    It just calls CreateProcess with the CREATE_NEW_PROCESS_GROUP flag bit set. See Win32::Process for the details.

    It's a bit more complicated as it has to arrange for wait and waitpid to work.


    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://547206]
Approved by jeffa
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-12-25 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls