开发者

Pass the pipe character from a DOS batch script in a CALL statement

开发者 https://www.devze.com 2023-02-20 22:28 出处:网络
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.

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 -d开发者_运维问答elimeter "$"

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


The following works for me:

call delim -delimiter "|"

and then using it like this in the called batch:

setlocal enabledelayedexpansion
set "delim=%~2"
echo Delimiter: !delim!


These versions should work cmd /c "test2.bat "^|"" and cmd /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 a call statement (outside of quotes), at least without the special caret trick.

Example

set "caret=^"
call echo &
call echo ^&
call echo ^^&
call echo ^^^&
call echo "&"
call echo %%caret%%^&

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消