Emulating system('COMMAND &') on Windows without using fork()

Discussion in 'Perl Misc' started by Jacob JKW, Jun 20, 2008.

  1. Jacob JKW

    Jacob JKW Guest

    I'm trying to emulate the UNIX behavior of system('COMMAND &') on
    Windows without having to use fork().

    I'd like to avoid this because the overhead of copying all data by
    value to the child process is rather substantial. Furthermore, were I
    to use fork() I'd eventually having to deal with the unintended
    consequences of methods called by the eventual object destruction in
    the child process.

    Thanks in advance.
     
    Jacob JKW, Jun 20, 2008
    #1
    1. Advertising

  2. Jacob JKW

    Willem Guest

    Jacob JKW wrote:
    ) I'm trying to emulate the UNIX behavior of system('COMMAND &') on
    ) Windows without having to use fork().

    Why not use the standard windows functionality?
    IIRC, it was system('start COMMAND').


    SaSW, Willem
    --
    Disclaimer: I am in no way responsible for any of the statements
    made in the above text. For all I know I might be
    drugged or something..
    No I'm not paranoid. You all think I'm paranoid, don't you !
    #EOT
     
    Willem, Jun 20, 2008
    #2
    1. Advertising

  3. Jacob JKW

    Guest

    Jacob JKW <> wrote:
    > I'm trying to emulate the UNIX behavior of system('COMMAND &') on
    > Windows without having to use fork().


    Have you tried:

    system(1,'COMMAND')

    I don't if it will work for your purposes, but it's the first thing I'd
    try.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
     
    , Jun 20, 2008
    #3
  4. Jacob JKW

    Jacob JKW Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    On Jun 20, 11:24 am, Willem <> wrote:
    > Jacob JKW wrote:
    >
    > ) I'm trying to emulate the UNIX behavior of system('COMMAND &')  on
    > ) Windows without having to use fork().
    >
    > Why not use the standard windows functionality?
    > IIRC, it was system('start COMMAND').

    Because until now I was blissfully unaware of its existence.

    It looks very promising. (Only problem is that it seems to pull up a
    command window with each invocation.. Clearly not a Perl issue,
    however.)

    Thank you very much. Highly appreciated.
     
    Jacob JKW, Jun 20, 2008
    #4
  5. Jacob JKW

    Jacob JKW Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    On Jun 20, 11:40 am, wrote:
    > Jacob JKW <> wrote:
    > > I'm trying to emulate the UNIX behavior of system('COMMAND &')  on
    > > Windows without having to use fork().

    >
    > Have you tried:
    >
    > system(1,'COMMAND')
    >
    > I don't if it will work for your purposes, but it's the first thing I'd
    > try.

    No, I hadn't tried it, but very preliminary testing looks promising.
    (I only fear that it may still be a fork() behind the scenes -- I'll
    have it to test that further).

    But anyway, where is this behavior documented? The perl doc on the
    system command doesn't appear to it mention at all.

    Many thanks and much appreciated.
     
    Jacob JKW, Jun 20, 2008
    #5
  6. Jacob JKW

    Jacob JKW Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    On Jun 20, 12:09 pm, Jacob JKW <> wrote:
    > On Jun 20, 11:24 am, Willem <> wrote:> Jacob JKW wrote:
    >
    > > ) I'm trying to emulate the UNIX behavior of system('COMMAND &')  on
    > > ) Windows without having to use fork().

    >
    > > Why not use the standard windows functionality?
    > > IIRC, it was system('start COMMAND').

    >
    > It looks very promising. (Only problem is that it seems to pull up a
    > command window with each invocation.. Clearly not a Perl issue,
    > however.)

    Even if clearly not a Perl issue it turns out that the way to avoid
    the creation of a new window is with the /B switch so:

    system('start /B COMMAND');
     
    Jacob JKW, Jun 20, 2008
    #6
  7. Jacob JKW

    Willem Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    Jacob JKW wrote:
    ) No, I hadn't tried it, but very preliminary testing looks promising.
    ) (I only fear that it may still be a fork() behind the scenes -- I'll
    ) have it to test that further).
    )
    ) But anyway, where is this behavior documented? The perl doc on the
    ) system command doesn't appear to it mention at all.

    This basically has nothing to do with perl.

    start is a windows CLI command.
    I think you can type 'help start' in a dos box.
    Or otherwise, websearch for it.

    I think there are also options to suppress the popup dosbox,
    although that may be in the perl Win32 package.


    SaSW, Willem
    --
    Disclaimer: I am in no way responsible for any of the statements
    made in the above text. For all I know I might be
    drugged or something..
    No I'm not paranoid. You all think I'm paranoid, don't you !
    #EOT
     
    Willem, Jun 20, 2008
    #7
  8. Jacob JKW

    Ted Zlatanov Guest

    On Fri, 20 Jun 2008 06:39:54 -0700 (PDT) Jacob JKW <> wrote:

    JJ> I'm trying to emulate the UNIX behavior of system('COMMAND &') on
    JJ> Windows without having to use fork().

    JJ> I'd like to avoid this because the overhead of copying all data by
    JJ> value to the child process is rather substantial. Furthermore, were I
    JJ> to use fork() I'd eventually having to deal with the unintended
    JJ> consequences of methods called by the eventual object destruction in
    JJ> the child process.

    To avoid fork penalties, you can fork early and communicate between
    processes as needed.

    Ted
     
    Ted Zlatanov, Jun 20, 2008
    #8
  9. Jacob JKW

    Jacob JKW Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    On Jun 20, 12:17 pm, Willem <> wrote:
    > Jacob JKW wrote:
    >
    > ) No, I hadn't tried it, but very preliminary testing looks promising.
    > ) (I only fear that it may still be a fork() behind the scenes -- I'll
    > ) have it to test that further).
    > )
    > ) But anyway, where is this behavior documented? The perl doc on the
    > ) system command doesn't appear to it mention at all.
    >
    > This basically has nothing to do with perl.
    >
    > start is a windows CLI command.
    > I think you can type 'help start' in a dos box.
    > Or otherwise, websearch for it.
    >
    > I think there are also options to suppress the popup dosbox,
    > although that may be in the perl Win32 package.

    The post to which you're replying was my reply to xhos post where he
    had suggested system(1,COMMAND);

    I was asking where *that* was documented.

    Perhaps I need a better news client than Google. ;)
     
    Jacob JKW, Jun 20, 2008
    #9
  10. Jacob JKW

    Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    Jacob JKW <> wrote:
    > On Jun 20, 11:40=A0am, wrote:
    > > Jacob JKW <> wrote:
    > > > I'm trying to emulate the UNIX behavior of system('COMMAND &') =A0on
    > > > Windows without having to use fork().

    > >
    > > Have you tried:
    > >
    > > system(1,'COMMAND')
    > >
    > > I don't if it will work for your purposes, but it's the first thing I'd
    > > try.


    > No, I hadn't tried it, but very preliminary testing looks promising.
    > (I only fear that it may still be a fork() behind the scenes -- I'll
    > have it to test that further).


    I don't think it uses fork, as I don't think windows *has* a real fork.
    Perl's fork on windows is emulated using threads, but I doubt they used
    used that emulation to implement system(1,...). The point of having
    a special system(1,..) on Windows is to use a technology which is better
    matched to the underlying OS.

    > But anyway, where is this behavior documented? The perl doc on the
    > system command doesn't appear to it mention at all.


    It is in the "system" section of perldoc perlport. It probably should
    be mentioned under perldoc -f system as well, and maybe perldoc -q
    background.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
     
    , Jun 20, 2008
    #10
  11. Jacob JKW

    Willem Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    Jacob JKW wrote:
    ) The post to which you're replying was my reply to xhos post where he
    ) had suggested system(1,COMMAND);
    )
    ) I was asking where *that* was documented.
    )
    ) Perhaps I need a better news client than Google. ;)

    Nope, that was my fault, I replied to the wrong post. Sorry.


    SaSW, Willem
    --
    Disclaimer: I am in no way responsible for any of the statements
    made in the above text. For all I know I might be
    drugged or something..
    No I'm not paranoid. You all think I'm paranoid, don't you !
    #EOT
     
    Willem, Jun 20, 2008
    #11
  12. Jacob JKW

    Ben Morrow Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    Quoth Jacob JKW <>:
    > On Jun 20, 11:40 am, wrote:
    > > Jacob JKW <> wrote:
    > > > I'm trying to emulate the UNIX behavior of system('COMMAND &')  on
    > > > Windows without having to use fork().

    > >
    > > Have you tried:
    > >
    > > system(1,'COMMAND')
    > >
    > > I don't if it will work for your purposes, but it's the first thing I'd
    > > try.

    > No, I hadn't tried it, but very preliminary testing looks promising.
    > (I only fear that it may still be a fork() behind the scenes -- I'll
    > have it to test that further).


    It doesn't. It is an ancient ActiveState hack to directly invoke Win32's
    spawn* family of functions.

    > But anyway, where is this behavior documented? The perl doc on the
    > system command doesn't appear to it mention at all.


    perlport, under "Function Descriptions/system". Not perhaps the first
    place one would look, but if you're using perl on a non-Unix platform
    you really need to read perlport all the way through.

    Ben

    --
    For far more marvellous is the truth than any artists of the past imagined!
    Why do the poets of the present not speak of it? What men are poets who can
    speak of Jupiter if he were like a man, but if he is an immense spinning
    sphere of methane and ammonia must be silent? [Feynmann]
     
    Ben Morrow, Jun 20, 2008
    #12
  13. Jacob JKW

    Jacob JKW Guest

    Re: Emulating system('COMMAND &') on Windows without using fork()

    On Jun 20, 12:39 pm, wrote:
    > Jacob JKW <> wrote:
    > > On Jun 20, 11:40=A0am, wrote:
    > > > Jacob JKW <> wrote:
    > > > > I'm trying to emulate the UNIX behavior of system('COMMAND &') =A0on
    > > > > Windows without having to use fork().

    >
    > > > Have you tried:

    >
    > > > system(1,'COMMAND')

    >
    > > > I don't if it will work for your purposes, but it's the first thing I'd
    > > > try.

    > > But anyway, where is this behavior documented? The perl doc on the
    > > system command doesn't appear to it mention at all.

    >
    > It is in the "system" section of perldoc perlport.  It probably should
    > be mentioned under perldoc -f system as well, and maybe perldoc -q
    > background.

    Yeah, if that had been added to perldoc -f system that certainly would
    have made my life a lot easier.

    Thanks again for all your help. :)
     
    Jacob JKW, Jun 20, 2008
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Niall Smart
    Replies:
    1
    Views:
    1,808
    Dimitre Novatchev [MVP XML]
    Mar 5, 2004
  2. boriq
    Replies:
    4
    Views:
    598
    Tim Golden
    Jun 12, 2008
  3. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    579
    Eric Snow
    Jan 8, 2009
  4. Ethan Huo
    Replies:
    4
    Views:
    150
    Ethan Huo
    Apr 2, 2011
  5. Chris Jakeman
    Replies:
    1
    Views:
    127
    Markus Ernst
    Jul 17, 2003
Loading...

Share This Page