DrWhy has asked for the wisdom of the Perl Monks concerning the following question:

Greetings PerlMonks,

I am working on a script to run all of our regression test scripts from Windows' cron (aka Scheduled Tasks), and then produce a summary report. I'm planning to go through Test::Harness::Straps to execute the test scripts. THS executes the test scripts via a piped open (open(FILE, "$command |")). This will catpure stdout, but will let stderr go on it's merry way. I'd like to capture the stderr in my script. Does anyone know of a good (actually it doesn't have to be good, it just has to work;) way to do that?

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

  • Comment on Capturing stderr from a test script executed by Test::Harness::Straps

Replies are listed 'Best First'.
Re: Capturing stderr from a test script executed by Test::Harness::Straps
by chromatic (Archbishop) on Oct 18, 2005 at 01:33 UTC
Re: Capturing stderr from a test script executed by Test::Harness::Straps
by saintmike (Vicar) on Oct 17, 2005 at 23:30 UTC
      Ah. Good advice. I will look into these.

      update: adrianh is correct. To clarify, I'm interested in capturing the stderr of the test script itself, not testing the stderr produced by the code under test.

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

      Check out Test::Output and Test::Output::Tie.

      Nope. These are for testing things that output to STDERR (and other filehandles), not for capturing the STDERR output from test scripts :-)

      For the latter look at analyze() from Test::Harness::Straps and use some kind of IPC3/Run3 variant to capture STDERR. See Quiet test runner for an example.

Re: Capturing stderr from a test script executed by Test::Harness::Straps
by graff (Chancellor) on Oct 18, 2005 at 00:24 UTC
    Something that might work (maybe), would be to open like this:
    open( FILE, "$command 2>&1 |" );
    What that does (if it works) is to put both STDERR and STDOUT together into the pipe. But then you have to know how to separate the error output from the non-error output, which might be a problem... (There shouldn't be any problem with lines being broken, but the relative ordering of stderr lines vs. stdout lines is not likely to be predictable or even consistent.)

    I have a suspicion that it might not work on all OS's -- it should work on any unix-like system.)

      Yes, this solution occurred to me as well, and in fact the postprocessing that THS does would effectively separate the stdout (test result lines) and stderr (diag lines) as long as the test script conformed exactly to the TAP protocol, but that would entail modifying THS itself, a CPAN module not written or maintained by me, something which I am not willing to do at this point.

      I was hoping there might be some way to redfine/manipulate STDERR in my script in order to capture it, but I suspect this will not work, since the test script is running in a separate process.

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."