I wrote this for unix:
sub phork {
# we will call fork and return a pid. The child will exec with all args
# and suppress the child's output (with /dev/null);
my $pid;
if ($pid = fork) { # fork the process;
#parent
return $pid;
}else
{
#child
die "CANNOT FORK!!\n" unless defined $pid;
open(STDOUT, "/dev/null"); # suppressing output
open(STDERR, "/dev/null"); # suppressing output
{exec(@_);}; # calls exec with current @_
exit(1); # exec may maybe fail... maybe.
}
}
now, if you used the opens to open pipes,
or to open files you want the output in, I'm thinking
it should work in windows too.
I have a question, however, regarding how one would
just disregard STDOUT and STDERR under windows using
this function (there's no /dev/null of course).
Also, when you reap the forked process, you can then
get the return value ($exit_value = $? >> 8;) if you
don't want asynchronocity, then replace exec with
system, and you can get the return value directly from that.
-Daniel