24

I need to pass parameter line AB CD to a batch file from the command line. This parameter refer to a file name.

If I use use AB CD the script just pick the first part and return Unable to find the file AB.txt

If I put quote around my parameters like "AB CD" the I got

"AB CD".txt 
Illegal characters in path.
4

3 回答 3

38

您可以使用 %~1 代替 %1

例如一个 test.bat :

echo %~1

然后调用test "abc de"将显示:

abc de
于 2013-09-05T15:12:28.923 回答
13

你能做的是

>batch.bat "ab cd.txt"

当参数包含空格时,您可以将它们括在引号中。

于 2013-09-05T15:01:05.680 回答
0

如果它只接受 1 个参数"%*",则不需要引用参数

myapp.cmd

@echo off
echo "%*"

测试一下

myapp single parameter with space
于 2020-12-23T15:53:44.530 回答