Greetings. I have some code that runs beautifully under Perl 5.004_04 on Solaris 6. We are in the process of upgrading our server to Solaris 9 and in the process, upgrading Perl to 5.8.0. I have been testing the scripts that we currently have in production on the on Solaris 6 with the new OS and Perl. Everything this seems to work fairly well, however, I have noticed one problem. I am dup'ing STDOUT and STDERR to a log file so that if there is output from some of the external programs we run, we can capture it. This runs perfectly under the older version of Perl. However, the same code does not behave quite the same under Perl 5.8.0.

Example of code in question:

open (STDOUT, ">$log_dir/$process.log") or exit 1; open (STDERR, ">&STDOUT") or exit 2; flock(STDOUT, LOCK_EX | LOCK_NB) or exit 3; truncate STDOUT, 0; #clear out STDOUT to start with a fresh log file. print "This is my log file.\n"; qx!someprogramtorun!; (do some more stuff) __DATA__ (what I see in the log file) This is my log file.

With the older version, I would also have captured the output from qx!someprogramtorun!. However, that is not being captured when run under Perl 5.8.0. Now, this is not a big problem for most external programs we use, but it causes one that we run to error out for some inexplicable reason. If I capture STDOUT and STDERR to a log file from the commandline with something like: my_program.pl >log.t 2>&1, everything runs perfectly. I capture both those lines that I want printed and anything incidental that the external programs throw out. I'm sure that what I am doing is not ideal, but it was working. I'd prefer not to have to do all the commandline redirections if it can be avoided. What am I missing? As far as I can determine, the output from qx!! is the only thing effected. I can't determine if the problem is with how I'm redirecting STDOUT and STDERR with open() or what.

Thanks in advance.

update: added line into code example to indicate that I need to retain control of the program after the qx!!.


"Ex libris un peut de tout"

In reply to Problem dup'ing STDOUT by nimdokk

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.