How to Pass Command Line Parameters with space in Batch File

前端 未结 3 1798
囚心锁ツ
囚心锁ツ 2021-01-03 21:05

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 scr

相关标签:
3条回答
  • 2021-01-03 21:15

    if it only accept 1 paramenter use "%*" you don't need to quote the parameter

    myapp.cmd

    @echo off
    echo "%*"
    

    test it

    myapp single parameter with space
    
    0 讨论(0)
  • 2021-01-03 21:27

    you can use %~1 instead of %1

    e.g a test.bat with :

    echo %~1
    

    then a call to test "abc de" will display :

    abc de
    
    0 讨论(0)
  • 2021-01-03 21:30

    what you can do is

    >batch.bat "ab cd.txt"
    

    When the parameters contain whitespace, you can enclose them in quotes.

    0 讨论(0)
提交回复
热议问题