Reputation: 11
The batch file outputs "The system cannot find the file specified." instead of redirecting the error to nul
set /p firstline=<text.txt >nul 2>nul
pause
What do I need to to do suppress error messages
Upvotes: 0
Views: 1156
Reputation: 8650
With this code redirection will be ignored. I'm not sure why, my guess is that because error happens in redirection mechanism itself, later redirs will never run.
To force separation of redirections where you expect errors - use ():
(set /p firstline=<text.txt) >nul 2>nul
You can also consider using different syntax to redirect everything to one ouptut:
(set /p firstline=<foo2.txt) >nul 2>&1
Upvotes: 1
Reputation: 3700
That does appear to be the case (tested on Win7). Seems like a bug-like feature. :-) If your batch file is simple enough, you could get around this by calling your batch file with 2>nul
(i.e., foo.cmd 2>nul
).
Alternately, you could put just that line in a batch file of its own (say, setfirstline.cmd
) and use call setfirstline.cmd 2>nul
from a "parent" batch file. Hacky, but functional.
Upvotes: 0