I am once again having a devil of a time. This time standard error is not working for me as it should!

In my code below, I want to run a command that test an image file. If the identify command creates an error, it should write the file name to error.txt. All other info should go to dump.txt.

dump.txt works well and captures all but the error info. However, error.txt captures all file names.

. . . RetrieveValues(); CheckImageArchieve(); sub RetrieveValues { print "\n\nSpecify the Directory path to image folder:\n"; $directory = (<STDIN>); chomp $directory; # $directory =~ s/\\/\\\\/g; } sub CheckImageArchieve { my $a = 0; opendir(DIR, $directory) or die "Cannot open directory $directory" +; my @DIR = grep {$_ ne '.' && $_ ne '..' && grep (m/fpx/, $_)} read +dir DIR; system ("cls"); while ($DIR[$a]) { print "$directory\\$DIR[$a]\n"; system("echo $directory\\$DIR[$a] >> c:\\dump.txt"); system("identify -verbose $directory\\$DIR[$a] >> c:\\dump.txt"); or system("echo ERROR: $directory\\$DIR[$a] >> c:\\error.txt") +; $a=$a+1; } }

In the past, when I have had trouble with opening files, I would use the same redirection and it would work. I difficulty arises here because i am using a command line utility. Is my code proper, or is the command causing the issue?

Please advise,
Simon

In reply to Redirecting errors by sdyates

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.