in reply to How to stop printing the output of a command on screen when the command fails?

perl_mystery:

Redirect the STDERR stream. In bash, for example, you can do:

p4 where filename 2>&1

This tells the p4 command to send the STDERR stream (handle 2) to handle 1 (STDOUT). I expect that the same syntax will likely work in backticks, but I've never tried it, so you'll need to verify that. There are multiple ways to redirect the I/O streams using perl, so you may want to read perldoc perlipc and perldoc -f open to start with.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: How to stop printing the output of a command on screen when the command fails?
by perl_mystery (Beadle) on Dec 24, 2010 at 05:24 UTC

    Roboticus,your suggesting doesnt seem to working,why is it so?

    foreach my $file (@changed_files) { my $p4where_output=`p4 where $file 2>&1`; print "P4 where output:$p4where_output\n"; if($p4where_output =~ /file(s) not in client view/) { push @changed_paths,"$file\n"; }
      Roboticus's suggestion should have worked, and is the simplest solution. Some programs (not many) do not write to stderr, but to the terminal driver direct. Check the documentation for the product you are using that it is actually writing to stderr. If that does not tell you, then run it under strace(1) or truss(1) to check (these are UNIX/Linux commands which trace kernel calls).

        What's confusing me is,if I run the below command from command prompt I see stderr getting supressed but where as when I run it in perl using backticks it fails,what could be going wrong>

        >p4 where //depot/perl/tools/files/data.c > NUL: 2>&1