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

Re: Re: Re: Re: Re: Closing parent CGI after fork()

by edan (Curate)
on May 31, 2004 at 14:04 UTC ( [id://357790]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Closing parent CGI after fork()
in thread Closing parent CGI after fork()

How do I go about re-opening STD(IN|OUT|ERR)?

This is what I did:

# throw away STDIN and STDOUT open STDIN, '<', '/dev/null'; open STDOUT, '>', '/dev/null'; # save STDERR to deal with later my $err_file = "/tmp/err.$$"; open STDERR, '>', $err_file;

If I close STDOUT, how do I get hold of my STDOUT from the perl script or more importantly the system call?

Well, as you see, you're not really closing STDOUT you are reopening it to some other place. This will cause all output that would ordinarily go to your program's standard STDOUT to go to the file specified in the open call above. That includes any output generated by system calls and the like, since it's going to the same filehandle, only in a child process in that case (system simply performs a fork and exec under the hood). If you needed to get your hands on that output, you'd have to direct it to a real file instead of /dev/null, as in the STDERR example above.

HTH

--
edan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://357790]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-18 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found