in reply to How can I redirect STDOUT and STDERR from a program on WIN32?

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

-Daniel

  • Comment on Re: How can I redirect STDOUT and STDERR from a program on WIN32?

Replies are listed 'Best First'.
Re: Answer: How can I redirect STDOUT and STDERR from a program on WIN32?
by matthewm (Initiate) on Jan 26, 2001 at 14:37 UTC
    use "nul:" instead of "/dev/null" on win32.