重定向命令行输出保持在命令窗口中显示错误信息 [英] Redirecting command-line output to keep error messages from showing in the command window
问题描述
我测试的文件夹的存在,并根据它的存在,我想运行不同的命令:
DIR%MYDIR%\\ tmp目录>的test.txt
IF ERRORLEVEL 1(
回声/文件夹不存在
)其他(
回声/文件夹是否存在
)
问题是,如果文件夹不存在,我除了在标准输出收到此错误:
系统找不到指定的文件。
我想没有得到错误,以显示正确的输出。
这个怎么样:
DIR%MYDIR%\\ tmp目录> NUL 2 - ;&放大器; 1
> NUL是指标准输出重定向到文件NUL(比特斗)。
2>用于重定向标准误差(描述2)。因此,2>&安培; 1被用来重定向标准错误意味着标准输出(描述符1 - 所以>空1> NULL的是相同的)或者,您可以使用。2> NUL。 p>
I'm testing the existence of a folder, and, depending on its existence, I want to run different commands:
DIR %MYDIR%\tmp > test.txt
IF ERRORLEVEL 1 (
echo/FOLDER DOES NOT EXIST
) else (
echo/FOLDER EXISTS
)
The problem is that if the folder doesn't exist I'm getting this error in addition to the standard output:
The system cannot find the file specified.
I'd like to display the correct output without getting the error.
How about this:
DIR %MYDIR%\tmp > nul 2>&1
"> nul" means to redirect standard output to the file nul (the bit bucket).
"2>" is used to redirect standard error (descriptor 2). So "2>&1" is used to redirect standard error to means that standard output (descriptor 1 -- so "> null and 1> null are be the same). Alternatively you could use "2> nul".
这篇关于重定向命令行输出保持在命令窗口中显示错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!