Windows cmd文件显示错误没有复制

时间:2016-01-18 09:40:57

标签: windows batch-file cmd

当我从java执行下面的copyWindows.cmd文件时,它会打开新窗口并显示如下输出。 请帮忙。

copyWindows.cmd:

@echo off
@echo Copying Test Content to Server
IF NOT EXIST %1 GOTO testContentNotExist
IF NOT EXIST %2 GOTO radBatDirNotExist
copy /Y %1 %2
goto success
:testContentNotExist
@echo The test content %1 does not exist
exit 2

:radBatNotExist
@echo The rad Bat Directory %2 does not exist
exit 2

:success
@echo The test content %1 successfully copied to dir %2

输出:

Copying Test Content to Server
'testNotExist' is not recognized as an internal or external command,
operable program or batch file.
'radBatNotExist' is not recognized as an internal or external command,
operable program or batch file.
The syntax of the command is incorrect.
The test content  successfully copied to dir

由于

1 个答案:

答案 0 :(得分:2)

你的问题就在这一行:

IF NOT EXIST %1 GOTO testContentNotExist

语法为IF NOT EXIST filename COMMAND

如果%1为空,则此行计算为:

IF NOT EXIST GOTO testContentNotExist

因此它搜索名为GOTO的文件,它找不到并尝试执行testContentNotExist - 这不是一个有效的命令。

使用以下方法避免:

IF NOT EXIST "%~1" GOTO testContentNotExist

(与下一行相同)