我是编写代码和批处理文件的新手。我正在尝试通过允许用户发出以下批处理文件来自动化用户设置:
执行的命令 = "BVT_AudioDecode_Setup.bat V:\WP\BVT\Audio\Decode 10.42.233.237"
@echo off
::Conditions leading to errors if the batch script is not executed correctly
if "%1"=="" and "%2"=="" goto error1
if "%1"=="" goto error2
if "%2"=="" goto error3
::Allows user to set the "Source Path" to copy the testcase files from
set source=%1
::Allows user to set the "Destination Path" to copy the testcase files from
set IP_Address=%2
::Tells the user what the "Source" and "Destination" Paths are
echo Source Path = %1
echo Destination Path = %2
echo.
powershell.exe -File "bat_script.ps1" %1 %2 -NoProfile -NoExit
goto end
:error1
echo.
echo Error Syntax: BVT_AudioDecode_Setup.bat "Source_Path\AudioDecode_Testcase_Folder" "Device IP Address"
echo.
echo For example: BVT_AudioDecode_Setup.bat V:\WP\BVT\Audio\Decode 10.42.233.237
echo -or-
echo BVT_AudioDecode_Setup.bat C:\WP\BVT\Audio\Decode 10.42.233.237
echo.
echo.
goto end
:error2
echo.
echo Error Syntax: BVT_AudioDecode_Setup.bat "Source_Path\AudioDecode_Testcase_Folder" "Device IP Address"
echo.
echo For example: BVT_AudioDecode_Setup.bat V:\WP\BVT\Audio\Decode 10.42.233.237
echo -or-
echo BVT_AudioDecode_Setup.bat C:\WP\BVT\Audio\Decode 10.42.233.237
echo.
echo.
goto end
:error3
echo.
echo Error Syntax: BVT_AudioDecode_Setup.bat "Source_Path\AudioDecode_Testcase_Folder" "Device IP Address"
echo.
echo For example: BVT_AudioDecode_Setup.bat V:\WP\BVT\Audio\Decode 10.42.233.237
echo -or-
echo BVT_AudioDecode_Setup.bat C:\WP\BVT\Audio\Decode 10.42.233.237
echo.
echo.
goto end
:end
这已经过测试并且有效。
现在我正在尝试添加/测试一个简单的代码块,但我找不到正确的语法。是的,过去 3 个小时我一直在谷歌上搜索。这是我正在尝试做的事情:
执行的命令 = "Random.bat C:\Users"
执行的命令 = "Random.bat C:\InvalidDirectory"
::Conditions leading to errors if the batch script is not executed correctly
@ECHO OFF
SET "mypath=%1"
ECHO %mypath%
cd %mypath% | find "%invalidpath%"
Echo %invalidpath%
If "%invalidpath%=The system cannot find the path specified." (
goto error1)
else (
goto BeginTest)
::Begins the testcase
:BeginTest
::Do some stuff
goto end
:error1
echo Error: Invalid Path
goto end
:end
如果有人能指出我正确的方向,将不胜感激......