tags:

views:

47

answers:

4
    open UNIT_TESTER, qq(tcsh -c "gpath $dir/$tsttgt;  bin/rununittests"|);
    while(<UNIT_TESTER>){
        reportError($ignore{testabort},$tsttgt,"test problem detected for $tsttgt:$_ ") if /core dumped/;
        reportError($ignore{testabort},$tsttgt,"test problem detected for $tsttgt:$_ ") if /\[  FAILED  \]/;
        writelog($tsttgt,$_);
    }
    close UNIT_TESTER;

I have tried to redirect stderr to stdout using this syntax but it didn't work:

open UNIT_TESTER, qq(tcsh -c "gpath $dir/$tsttgt;  bin/rununittests >& "|);

I have also read the discussion on the perl FAQ but that was in relation to bash: http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q5.15.html

+1  A: 

Try redirecting handle 2 (stderr) to handle 1 (stdout) as follows.

open UNIT_TESTER, qq(tcsh -c "gpath $dir/$tsttgt; bin/rununittests 2>&1 "|);

BillThor
That's Bourne/Korn/POSIX/Bash shell notation; not 'tcsh' unless it has had a serious makeover.
Jonathan Leffler
+1  A: 

Two options (at least) spring to mind:

open UNIT_TESTER, qq(tcsh -c "gpath $dir/$tsttgt >&;  bin/rununittests >& "|);

and

open UNIT_TESTER, qq(sh -c "{ gpath $dir/$tsttgt;  bin/rununittests; } 2>&1"|);

The second is a cheat; it uses Bourne/Korn/POSIX/Bash shell notation. Note that unless you are careful, you end up with the error output of only the second command and not of the first.

Jonathan Leffler
Unfortunately I actually need to run these commands in tcsh.
mikelong
@mikelong: If you think that it must be tcsh, then you need to be sent to look for [C Shell Programming Considered Harmful](http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/). Also, with care, you could use: `qq(tcsh -c "sh -c '{ ... ; } 2>` which uses `tcsh` to run `sh` to capture the output. If you're careful, you can use 'exec' in there too.
Jonathan Leffler
A: 

Thanks to BillThor I stumbled upon a solution:

open UNIT_TESTER, qq(tcsh -c "gpath $dir/$tsttgt;  bin/rununittests |& cat "|);
mikelong
Does that capture errors from the `gpath` command?
Jonathan Leffler
No it doesn't, but I actually only need the output from the second command.
mikelong
+2  A: 

I would suggest you do your capturing with the Capture::Tiny module from CPAN. It's small, simple, and well tested. It has an elegant API and if you totally can't have any dependencies, it can be embedded into your program easily.

Apart from that: If you have any control over the testing program being run, I would suggest you investigate the Test Anything Protocol. If you can make your test program output TAP, then your use case including a nice summary of the tests becomes as simple as:

perl -MTest::Harness -e 'runtests(@ARGV)' bin/rununittests

NB about the second paragraph: Potentially recent Test::Harness required. Also, doesn't quite do what you need regarding the shell invocation, but it should get you close enough.

tsee