nycfdtd
nycfdtd

Reputation: 404

How to ignore a specific command-line error output from batch script?

I have made a batch script that, among other things, merges our DEV branch to our TEST branch using the following command:

tf merge $/Proj/Dev $/Proj/Test /recursive >nul

This command always triggers the following output:

TF401190: The local workspace [workspace];[name] has 110500 items in it, which exceeds the recommended limit of 100000 items. 
To improve performance, either reduce the number of items in the workspace, or convert the workspace to a server workspace.

I know I can avoid all errors/ouput by adding "2>&1" to the end of the command like so:

tf merge $/Proj/Dev $/Proj/Test /recursive >nul 2>&1

Ideally I would just like to ignore/suppress specifically the TF401190 error. I feel like there has to be a way to do this, even if it means checking the output for a specific token/string before allowing it to print. I'm still very new to the command-line and batch scripts. Any help would be greatly appreciated! Thanks.

NOTE: I'm not interested in addressing a solution for the error itself. This question is only concerned with how to suppress any specific error.

Upvotes: 1

Views: 5084

Answers (2)

dbenham
dbenham

Reputation: 130919

The answer to this question is an extension to Is there a way to redirect ONLY stderr to stdout (not combine the two) so it can be piped to other programs?

You need to redirect stderr and stdout in such a way that only errors are output, and pipe the error messages a FIND or FINDSTR command that filters out the messages you don't want.

tf merge $/Proj/Dev $/Proj/Test /recursive 2>&1 >nul | findstr /b ^
  /c:"TF401190: The local workspace " ^
  /c:"To improve performance, either reduce the number of items in the workspace, or convert the workspace to a server workspace."

I've used line continuation to make the code a bit easier to read.

Upvotes: 0

Rudi Cilibrasi
Rudi Cilibrasi

Reputation: 885

In the bash shell, you can filter out specific errors like this:

ls /nothere

ls: cannot access /nothere: No such file or directory

To suppress that specific error message:

ls /nothere 2>&1 | grep -v 'No such file'

(error message is suppressed)

Checking if other error messages get through:

ls /root 2>&1 | grep -v 'No such file'
ls: cannot open directory /root: Permission denied

(other error messages get through fine)

Upvotes: 1

Related Questions