在 CALL 语句中传递来自 DOS 批处理脚本的管道字符
在 DOS 批处理脚本(需要在 Win 200x 和 Win7 环境中运行)中,我需要将引号中的特定字符传递给另一个可执行文件;例如,
doparse -delimeter "$"
一般来说,这是可行的:
CALL CMD /C "doparse -delimeter "$""
不幸的是,我需要指定管道字符作为分隔符(这是一个要求)。我预计以下内容会起作用:
CALL CMD /C "doparse -delimeter "^|""
但是当我运行脚本时,我根本看不到该行的任何输出(例如,如果我用一些不存在的名称替换“doparse”,则不会出现错误消息)。
我尝试了转义字符的各种组合,但无法使其工作。是否可以? (不幸的是,必须通过批处理脚本完成)。
谢谢
within a DOS batch script (that needs to run in the Win 200x and Win7 environments) I need to pass a particular character, in quotes, to another executable; e.g.
doparse -delimeter "$"
In general this works:
CALL CMD /C "doparse -delimeter "$""
Unfortunately, I need to specify the pipe character as the delimeter (this is a requirement). I expected the following would work:
CALL CMD /C "doparse -delimeter "^|""
But when I run the script I don't see any output at all for this line (e.g. no error message if I replace "doparse" with some non-existent name).
I've tried various combinations of escape chars but cannot get it to work. Is it possible? (Has to be done via a batch script, unfortunately).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下对我有用:
然后在调用的批处理中像这样使用它:
The following works for me:
and then using it like this in the called batch:
这些版本应该可以使用
cmd /c "test2.bat "^|""
和cmd /c ^"test2.bat "|""
。两者都会启动 test2.bat。
乔伊的版本也有效。
您的情况的问题是
call
和引号的数量,不可能转义call
语句中的特殊字符(引号之外),至少没有特殊字符插入符技巧。示例
只有最后两个有效,第一个在引号内,第二个在使用特殊插入符技巧运行的第二个解析器中转义
&
。在您的情况下,
|
位于引号之外(在第二个引号之后)。cmd.exe 中存在一个错误,因此如果解析器在调用阶段后发现未转义的
&
或|<>
,它会立即停止。These versions should work
cmd /c "test2.bat "^|""
andcmd /c ^"test2.bat "|""
.Both starts the test2.bat.
Also the version of Joey works.
The problem in your case is the
call
and the number of quotes, it's not possible to escape special characters in acall
statement (outside of quotes), at least without the special caret trick.Example
Only the last two works, the first is inside of quotes and the second escapes the
&
in the second parser run with the special caret trick.In your case the
|
is outside of the quotes (it's after the second quote).And there is a bug in cmd.exe so it immediatly stops, if the parser founds a unescaped
&
or|<>
after a call phase.