Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 在命令提示符中使用变量_Batch File_Command Prompt - Fatal编程技术网

Batch file 在命令提示符中使用变量

Batch file 在命令提示符中使用变量,batch-file,command-prompt,Batch File,Command Prompt,我在命令提示符中使用变量时遇到问题。根据环境变量的值,我想在批处理文件中执行几个命令。代码如下: SET CONFIGURATION=Release if "CONFIGURATION"=="Release" (copy c:\python26\test1.py d:\testfiles copy c:\case.jpg d:\images ) else (copy c:\python26\test2.py d:\testfiles copy c:\debug.jpg d:\images )

我在命令提示符中使用变量时遇到问题。根据环境变量的值,我想在批处理文件中执行几个命令。代码如下:

SET CONFIGURATION=Release

if "CONFIGURATION"=="Release"
(copy c:\python26\test1.py d:\testfiles
copy c:\case.jpg d:\images
)
else
(copy c:\python26\test2.py d:\testfiles
copy c:\debug.jpg d:\images
)

这就是我想做的。我不熟悉使用这种脚本。所以我没有太多的信息。请帮我解决这个问题。

稍后使用变量时,设置后,您将用百分号围绕变量,如下所示:

if %CONFIGURATION% == "release" ...

批处理文件具有某种特殊的语法

所以你的代码应该是

SET CONFIGURATION=Release

if "%CONFIGURATION%"=="Release" (
  copy c:\python26\test1.py d:\testfiles
  copy c:\case.jpg d:\images
) else (
  copy c:\python26\test2.py d:\testfiles
  copy c:\debug.jpg d:\images
)

重要的是,括号应位于
if
ELSE

的同一行中。嗨,Gabriel,谢谢您的帮助。但它似乎对我不起作用。我就是这么做的。如果%configuration%=“release”(回显成功)或“else”(回显失败),则设置configuration==release。此打印失败:|