cod*_*der 2 windows batch-file
这看起来很简单,但我很困惑 - 一直在寻找很多几乎匹配的问题,但却找不到答案.
我想做的就是这样:
echo c:\another\test\file.h(22,11) : warning 123: this is a test warning
Run Code Online (Sandbox Code Playgroud)
但这给出了错误:: was unexpected at this time.
所以我尝试过:
echo "c:\another\test\file.h(22,11) : warning 123: this is a test warning"
Run Code Online (Sandbox Code Playgroud)
产生:"c:\another\test\file.h(22,11) : warning 123: this is a test warning".但我不想要报价.所以我尝试使用转义字符"^":
echo c^:\another\test\file.h(22,11) ^: warning 123^: this is a test warning
Run Code Online (Sandbox Code Playgroud)
但这没有效果.我怎样才能做到这一点?
更新:
这行代码在if块中,这似乎有所不同!:
if exist "somefile" (
echo c:\another\test\file.h(22,11) : warning 123: this is a test warning
)
我相信你的命令行放在一个paranthesised的代码块中,例如:
if exist "c:\another\test\file.h" (
echo c:\another\test\file.h(22,11) : warning 123: this is a test warning
)
Run Code Online (Sandbox Code Playgroud)
所以封闭)在echo命令行解释为整个块的关闭一个,留下的部分: warning 123: this is a test warning作为无效命令行.
要解决这个问题,你需要在)一个插入符号之前进行转义^,这是cmd一个转义字符:
if exist "c:\another\test\file.h" (
echo c:\another\test\file.h(22,11^) : warning 123: this is a test warning
)
Run Code Online (Sandbox Code Playgroud)
因此:,前面的冒号warning: ...实际上并没有引起问题.
| 归档时间: |
|
| 查看次数: |
636 次 |
| 最近记录: |