如何在批处理文件中使用空格传递命令行参数 [英] How to Pass Command Line Parameters with space in Batch File

查看:203
本文介绍了如何在批处理文件中使用空格传递命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从命令行将参数行AB CD传递给批处理文件.此参数引用文件名.

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

如果我使用use AB CD,则只需选择脚本的第一部分并返回Unable to find the file AB.txt

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

如果我在诸如"AB CD"这样的参数周围加上引号,我会得到

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

"AB CD".txt 
Illegal characters in path.

推荐答案

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

you can use %~1 instead of %1

例如带有:的test.bat

e.g a test.bat with :

echo %~1

然后将显示对test "abc de"的呼叫:

abc de

这篇关于如何在批处理文件中使用空格传递命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆