For /f Quotes - Run a program with a long file name.
Posted: 2021-Aug-23, 8:12 am
Hi,
I have a program which accepts a string (may have spaces when surrounded by double quotes) as parameter and returns a string (may have spaces)
Like this :
"My Program Name.exe" "this is a string"
and the output might be "string a is this"
and that works
But if I want to capture the return-string in a variable with a
for /f %%i in ('"My Program Name.exe" "this is a string"') do set OutputString=%%i
I can't get it working
Tried several things :
for /f %%i in ('"My Program Name.exe"') do set OutputString=%%i --> program executes but does nothing as no given parameter
for /f %%i in ('"My Program Name.exe" "this is a string"') do set OutputString=%%i --> "My" is not recognized as an internal or external command
set aaa="this is a string"
for /f %%i in ('"My Program Name.exe" %%aaa%%') do set OutputString=%%i --> program executes but only |this| is passed to the program, meaning surrounding quotes are missing
set aaa=this is a string
for /f %%i in ('"My Program Name.exe" "%%aaa%%"') do set OutputString=%%i --> "My" is not recognized as an internal or external command
a.s.o.
What am I overlooking ?
I have a program which accepts a string (may have spaces when surrounded by double quotes) as parameter and returns a string (may have spaces)
Like this :
"My Program Name.exe" "this is a string"
and the output might be "string a is this"
and that works
But if I want to capture the return-string in a variable with a
for /f %%i in ('"My Program Name.exe" "this is a string"') do set OutputString=%%i
I can't get it working
Tried several things :
for /f %%i in ('"My Program Name.exe"') do set OutputString=%%i --> program executes but does nothing as no given parameter
for /f %%i in ('"My Program Name.exe" "this is a string"') do set OutputString=%%i --> "My" is not recognized as an internal or external command
set aaa="this is a string"
for /f %%i in ('"My Program Name.exe" %%aaa%%') do set OutputString=%%i --> program executes but only |this| is passed to the program, meaning surrounding quotes are missing
set aaa=this is a string
for /f %%i in ('"My Program Name.exe" "%%aaa%%"') do set OutputString=%%i --> "My" is not recognized as an internal or external command
a.s.o.
What am I overlooking ?