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


In reply to Re: Re: Re: Re: Re: Closing parent CGI after fork() by edan
in thread Closing parent CGI after fork() by hambo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.