I was using backticks as I needed to get the stderr and stdout.

But using backticks as you did doesn't capture the stderr of your system executable!

#!/usr/bin/env perl -w use strict; my $foo = qx{ ls }; # alternate syntax for backticks open my $fh, '>', 'bar.out' or die $!; print $fh $foo; close $fh; __END__
$ cat bar.out foo.pl $
#!/usr/bin/env perl -w use strict; my $foo = qx{ ls baz }; # doesn't exist open my $fh, '>', 'bar.out' or die $!; print $fh $foo; close $fh; __END__
$ cat bar.out $

You may have seen an error message spit out to your screen by your system executable, but it was not captured in your Perl program because you used backticks. You can combine the output streams, depending on your OS, with something like:

#!/usr/bin/env perl -w use strict; my $foo = qx{ ls baz 2>&1 }; open my $fh, '>', 'bar.out' or die $!; print $fh $foo; close $fh; __END__
$ cat bar.out ls: baz: No such file or directory $

But then you'll have to parse what you get to see if matches an error string. This all begs the question of why you didn't follow advice from others as well as myself to use a module that is built for the task ... because, among other benefits they usually handle errors gracefully.

Remember: Ne dederis in spiritu molere illegitimi!

In reply to Re^2: backtick iterpolation issue by 1nickt
in thread backtick iterpolation issue by idlehands

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.