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

$p4where_output =~ /file(s) not in client view/ probably is not doing what you think. The (s) matches and captures an 's' so the string matched is 'files not in client view' as I suspect you expect. More likely the regex you want is /files\(s\) not in client view/ to match the brackets. In fact it looks like you simply need a string match so you could: $p4where_output eq 'file(s) not in client view' instead.

True laziness is hard work

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 06:26 UTC

    Thanks for the suggestion grandfather but my problem is even after using 2>&1 as shown above,I still see stderr (not in client view messages)getting printed on the command prompt.I want to save it to the same variable "$p4where_output" and then proceed further

      I wasn't addressing your primary problem (although if you are using linux then try &2>1), but what appears to be a separate bug that will manifest itself when the current blocker bug is fixed.

      True laziness is hard work

        Hi, I am new to open3 and perldoc is too vague to understand I am trying a simple perforce command to run in open3.Basically I want to capture both STDOUT and STDERR aswell.I have tried various ways but none of them seem to be working.I am hoping someone will comment.

        foreach my $file (@changed_files) { #my $p4where_output=`p4 where $file > NUL: 2>&1`;#backticks option not + working,so commented out #print "P4 where output:$p4where_output\n"; my $cmd = "p4 where $file"; local(*HIS_IN, *HIS_OUT, *HIS_ERR); my $childpid = open3(*HIS_IN, *HIS_OUT, *HIS_ERR, p4 where $cmd); print HIS_IN "stuff\n"; close(HIS_IN); # Give end of file to kid. my @outlines = <HIS_OUT>; # Read till EOF. my @errlines = <HIS_ERR>; # XXX: block potential if massive print "STDOUT:\n", @outlines, "\n"; print "STDERR:\n", @errlines, "\n"; print @errlines; close HIS_OUT; close HIS_ERR; waitpid($childpid, 0); if ($?) { print "That child exited with wait status of $?\n"; } if(@errlines eq 'file(s) not in client view') { push @changed_paths,"$file\n"; } }