0

This is much simpler implementation of my actual batch files, but they serve purpose of illustrating my issue...

I have one batch file, b.cmd which simply echos the input argument:

REM - *** B.CMD
@echo off

echo %1
echo %~1

I have another batch file a.cmd which starts b.cmd:

REM - *** A.CMD
@echo off

set Location=C:\Users\yogi\AppData\Local\Temp\test
REM - This location could contain spaces, hence on the next line
REM - I am surrounding %Location%\b.cmd with QUOTEs.
start "" "%Location%\b.cmd" "Input Argument 1"

If I execute a.cmd, I get error:

'C:\Users\yogi\AppData\Local\Temp\test\b.cmd"  "Input' is not recognized as an internal or external command,
operable program or batch file.

However, if I remove QUOTEs around the %Location%\b.cmd from a.cmd, I get this (as I expected):

"Input Argument 1"
Input Argument 1

What am I doing wrong? I need QUOTEs around %Location%\b.cmd as well as input argument because both these could contain spaces.

Edited

Here is the output from a.cmd. Echo is on and b.cmd is called WITHOUT QUOTEs around it:

C:\Users\yogi\AppData\Local\Temp\test>a.cmd

C:\Users\yogi\AppData\Local\Temp\test>set Location=C:\Users\yogi\AppData\Local\Temp\test

C:\Users\yogi\AppData\Local\Temp\test>start "" C:\Users\yogi\AppData\Local\Temp\test\b.cmd "Input Argument 1"

C:\Users\yogi\AppData\Local\Temp\test>

Here is the output from b.cmd:

C:\Users\yogi\AppData\Local\Temp\test>echo "Input Argument 1"
"Input Argument 1"

C:\Users\yogi\AppData\Local\Temp\test>echo Input Argument 1
Input Argument 1

C:\Users\yogi\AppData\Local\Temp\test>

Here is the output from a.cmd. Echo is on and b.cmd IS called WITH QUOTEs around it:

C:\Users\yogi\AppData\Local\Temp\test>a.cmd

C:\Users\yogi\AppData\Local\Temp\test>set Location=C:\Users\yogi\AppData\Local\Temp\test

C:\Users\yogi\AppData\Local\Temp\test>start "" "C:\Users\yogi\AppData\Local\Temp\test\b.cmd" "Input Argument 1"

C:\Users\yogi\AppData\Local\Temp\test>

Here is the output from b.cmd:

'C:\Users\yogi\AppData\Local\Temp\test\b.cmd"  "Input' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\yogi\AppData\Local\Temp\test>
YogiWatcher
  • 165
  • 1
  • 8
  • Possible duplicate of [Why does windows START command not work with spaces in arguments AND path?](https://stackoverflow.com/questions/17674255/why-does-windows-start-command-not-work-with-spaces-in-arguments-and-path) – phuclv Jun 05 '19 at 17:12
  • since your path and parameters both have spaces it'll trigger the bug. One way to workaround is to use `call` – phuclv Jun 05 '19 at 17:13

1 Answers1

0

This works on my end.

start cmd /C ""%Location%\b.bat" "Input Argument 1""
Squashman
  • 13,649
  • 5
  • 27
  • 36