【发布时间】:2016-01-03 17:35:13
【问题描述】:
作为我正在进行的一些集成测试的一部分,我需要编写一个批处理文件,该批处理文件在 windows 框上回显到 stderr。目前我正在使用以下命令:
md %UserProfile%\tests\e3f949d1219d4cad9288bf88d0fcc906\ && cd %UserProfile%\tests\e3f949d1219d4cad9288bf88d0fcc906\ && ( echo @echo off && echo 'echo This is error line 1 1>&2' && echo 'echo This is error line 2 1>&2' && echo @echo on ) >>test-stderrout.bat
这应该在%UserProfile%\tests\ 目录下创建一个临时目录。然后导航到这个临时工作目录。然后使用以下代码创建一个批处理文件:
@echo off
echo This is error line 1 1>&2
echo This is error line 2 1>&2
@echo on
但是,文件包含:
@echo off
@echo on
我看到第一个回显被传送到标准错误中,而不是作为文本读取然后在批处理文件中。是否有可能以某种方式转义以允许输出包含重定向语句?
【问题讨论】:
-
一些特殊字符必须被转义。试试看:
echo echo This is some text 1^>^&2
标签: batch-file stderr