这是我实际批处理文件的简单得多的实现,但是它们的目的是说明我的问题...
我有一个批处理文件b.cmd,它只是回显输入参数:
REM - *** B.CMD
@echo off
echo %1
echo %~1
我还有另一个以b.cmd开始的批处理文件a.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"
如果我执行a.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.
但是,如果我从a.cmd中删除%Location%\ b.cmd附近的QUOTE,我会得到这个(正如我预期的那样):
"Input Argument 1"
Input Argument 1
我在做什么错?我需要%Location%\ b.cmd周围的QUOTE以及输入参数,因为这两个都可能包含空格。
已编辑
这是a.cmd的输出。 回显已打开,并且b.cmd周围没有报价 :
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>
这是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>
这是a.cmd的输出。 回显已打开并且b.cmd被引用为带有引号 :
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>
这是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>
答案 0 :(得分:0)
这对我有效。
yes