Passing a Batch File an Argument Containing a Quote Containing a Space

Posted by Synetech inc. on Stack Overflow See other posts from Stack Overflow or by Synetech inc.
Published on 2010-04-11T20:59:01Z Indexed on 2010/04/11 21:03 UTC
Read the original article Hit count: 235

Hi,

On many occasions I have dealt with passing batch files arguments with spaces, quotes, percents, and slashes and all sorts of combinations of them. Usually I managed to figure out how to accomplish what I want, but this time I am stuck. I have tried a couple of hundred combinations now and my head is starting to hurt.

I’ve reduced the problem quite nicely. It’s a simple requirement: pass a double-quoted space from one batch file to another. That is, one batch file should pass some string X to another so that the the second one echos " ". I just can’t figure out what X should be.

Here is a minimal batch file that demonstrates and attempt that does not work. (This BAT file takes the place of both by calling itself.)

::Goal is to print:
::" "
::That is, to pass a quoted space from a BAT file to a BAT file

if not (%1)==() goto recurse
%0 "" ""
:recurse
echo %1
pause

It does not work. I’ve tried using "\" \"", """ """, """" """", "\"" "\"", ""\" \""", "^" ^"", ^"" "^", and so on. Either they print double double-quotes, lose everything after the space, or something else (that is wrong).

Any ideas? Thanks.

© Stack Overflow or respective owner

Related posts about batch-file

Related posts about command-line-arguments