小编Maz*_*aka的帖子

带双引号的批处理文件多行命令

使用^符号输入带有参数的多行命令时使用双引号来使用带空格的字符串^符号也会被传递,有人可以解释这是什么方式吗?

working.cmd

@echo off 
call openfiles.cmd ^
C:\dir\filename.txt ^
C:\another_dir\another_file.txt
Run Code Online (Sandbox Code Playgroud)

notworking.cmd

@echo off 
call openfiles.cmd ^
"C:\dir with spaces\file with spaces.txt" ^
"C:\another dir with spaces\another file with spaces.txt"
Run Code Online (Sandbox Code Playgroud)

openfiles.cmd看起来像

@echo off
for %%x in (%*) do (

    IF EXIST %%x (
        call "c:\Program Files\Notepad++\notepad++.exe" %%x
    ) ELSE (
        call echo Not found %%x
    )

)

pause
Run Code Online (Sandbox Code Playgroud)

我得到的错误

C:\>call openfiles.cmd "C:\dir with spaces\file with spaces.txt" ^
ELSE was unexpected at this time.
Run Code Online (Sandbox Code Playgroud)

windows cmd batch-file

7
推荐指数
2
解决办法
8085
查看次数

标签 统计

batch-file ×1

cmd ×1

windows ×1