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 to a—fairly—simple requirement: pass from one batch file to another, an argument that contains some space-delimited text, one of which is a quoted space. That is, one batch file should pass some string X
to another so that the the second one echos "A "B C" D"
. I just can’t figure out what X
should be.
Here is a minimal batch file that demonstrates some attempts that do not work. (This BAT file takes the place of both by calling itself.)
::Goal is to print:
::"A "B C" D"
::ie., pass from one BAT file to another a quote containing spaces and a quote containing a space
@echo off
if not (%1)==() goto print
:passarg
call %0 "A "B C" D"
call %0 "A \"B C\" D"
%0 "A ""B C"" D"
:print
echo %1
pause
None of those attempts 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.
I'm new to the forum. Is quite cool, but never signed up until now.
I like the idea of calling a batch from another, very handy so you "pack" as much as possible into one single file.
I know this thread is old and hope I don't get banned or something lol
That outputs
Hope it helps!
Sorry about my messy script, I'm not too deep into programming ;)
This works
How about this workaround:
caller.bat:
callee.bat: