windows 将输入参数连接为在批处理文件中使用的变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5996607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Concatenating input parameters as variables for use inside batch file
提问by Mark
command line parameters are either fed to and read by batch file or hard coded in batch file
命令行参数要么由批处理文件提供和读取,要么在批处理文件中硬编码
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
并在bat文件执行时显示。但是,当它们中的两个连接在一起时
xcopy %SOURCE_URL%%SOURCE_DIR% d:\dqxi_7\reference_data /Y/H/S/R
they are not read. The command echoes as
他们没有读过。该命令回显为
xcopy d:\dqxi_7\reference_data /Y/H/S/R
How can I get these variables to work in the batch file to perform the work I need the bat file to perform (xcopy from the source server's reference_data_update directory to the target server's reference_data directory)?
如何让这些变量在批处理文件中工作以执行我需要 bat 文件执行的工作(xcopy 从源服务器的 reference_data_update 目录到目标服务器的 reference_data 目录)?
回答by Adam Straughan
try removing the spaces (near the set command)
尝试删除空格(在 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_7\reference_data /Y/H/S/R
回答by Richard Brightwell
Remove the spaces before and after your equals signs in you SET statements.
删除 SET 语句中等号前后的空格。