Mik*_*ail 4 command-line windows-8
在 linux 中,我可以输入echo "hello" >& text.output并在文件中获取文本输出。
如何在 Windows 8 中获得这种输出?
有没有办法从输出中判断错误?
我的动机是尝试记录输出tracert并调查 Windows 8 和 Windows 7 之间的差异。
与在 Linux 中的方式相同:
echo "Hello" >text.output
Run Code Online (Sandbox Code Playgroud)
错误通常打印到stderr流(它是#2)。您可以捕获stderr流:
del 1.txt 2>text.output
Run Code Online (Sandbox Code Playgroud)
如果文件1.txt不存在,text.output将包含Could not find 1.txt.
您可以重定向stdout到stderr:
echo "Hello" 2>&1
Run Code Online (Sandbox Code Playgroud)
或stderr到stdout:
echo "Hello" 1>&2
Run Code Online (Sandbox Code Playgroud)
PS 我不确定您的命令是否适用于 Linux。无论如何都会echo "hello" >& text.output产生语法错误:>& was unexpected at this time.
| 归档时间: |
|
| 查看次数: |
4017 次 |
| 最近记录: |