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

J

Jacob JKW

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.
 
W

Willem

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
 
X

xhoster

Jacob JKW said:
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.
 
J

Jacob JKW

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.
 
J

Jacob JKW

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.
 
J

Jacob JKW

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');
 
W

Willem

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
 
T

Ted Zlatanov

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
 
J

Jacob JKW

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. ;)
 
X

xhoster

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.
 
W

Willem

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
 
B

Ben Morrow

Quoth Jacob JKW said:
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
 
J

Jacob JKW

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. :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top