1

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.

nycfdtd
  • 404
  • 7
  • 23

2 Answers2

1

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)

Rudi Cilibrasi
  • 885
  • 4
  • 12
  • 2
    same princip in batch: `dir notexistent.bla" 2>&1|find /v "File Not Found` – Stephan Jul 09 '15 at 19:41
  • Thank you both for the response. Rudi, unfortunately I need the commands for a batch script, not bash. Stephan, by running a quick test in the command prompt I think your solution is going to work. I am going to try it on my script! – nycfdtd Jul 09 '15 at 22:18
  • Stephan, your solution works, but I think you have your quotations in the wrong place. I believe it should appear as so: `dir notexistent.bla 2>&1|find /v "File Not Found"` – nycfdtd Jul 09 '15 at 22:27
  • @nycfdtd you are right.I noticed it, but the timeframe for an edit was already closed. I guessed, you would figure it out yourself anyway ;) – Stephan Jul 10 '15 at 05:42
0

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.

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390