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

百般思念 提交于 2019-12-07 20:33:33

How about this workaround:

caller.bat:

@echo off
echo "A "B C" D">dummy.txt
call callee.bat

callee.bat:

@echo off
set /p argument=<dummy.txt
echo %argument%
pause

This works

@echo off
if not (%1)==() goto print
:passarg
  call %0 "A "B C" D"
:print
  echo %*

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

:Example.bat
@echo off

set SOMEARG=%1
set EXAMPLEARG=%2
set EXAMPLEARG=%EXAMPLEARG:""="%
set NEWFOLDER=%3
if not (%1)==() GOTO PRINT

CALL %0 SomeWord "Hey this arg has quoted "" "" spaces!" "C:\Program Files\Folder with spaces\Subfolder"

:PRINT
ECHO.
ECHO %0
ECHO %SOMEARG%
ECHO %EXAMPLEARG%
ECHO %NEWFOLDER%
ECHO.
pause

That outputs

"C:\SUT_Tools\Scripts\Testing\GLSU\Example.bat"
SomeWord
"Hey this arg has quoted " " spaces!"
"C:\Program Files\Folder with spaces\Subfolder"

Press any key to continue . . .

Hope it helps!

Sorry about my messy script, I'm not too deep into programming ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!