将输入参数连接为变量,以在批处理文件中使用

1 windows batch-file

命令行参数要么馈入批处理文件并通过批处理文件读取,要么在批处理文件中进行硬编码

Set Target_computer = %1
REM  Get Source URL
Set SOURCE_URL = %2
REM Set Source Directory
SET SOURCE_DIR = \reference_data_update
Run Code Online (Sandbox Code Playgroud)

并在执行bat文件时显示。但是,当其中两个串联时

xcopy %SOURCE_URL%%SOURCE_DIR% d:\dqxi\11_7\reference_data /Y/H/S/R
Run Code Online (Sandbox Code Playgroud)

他们没有被阅读。该命令回显为

xcopy    d:\dqxi\11_7\reference_data /Y/H/S/R
Run Code Online (Sandbox Code Playgroud)

如何使这些变量在批处理文件中工作以执行需要bat文件执行的工作(从源服务器的reference_data_update目录到目标服务器的reference_data目录的xcopy)?

Ada*_*han 5

尝试删除空格(在set命令附近)

@echo off
Set Target_computer=%1
REM  Get Source URL
Set SOURCE_URL=%2
REM Set Source Directory
SET SOURCE_DIR=\reference_data_update
::and display when bat file executes. However, when two of them are concatenated

echo %SOURCE_URL%%SOURCE_DIR% d:\dqxi\11_7\reference_data /Y/H/S/R
Run Code Online (Sandbox Code Playgroud)