Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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
Windows 为什么对标签的以下调用会退出脚本?_Windows_Batch File_Cmd - Fatal编程技术网

Windows 为什么对标签的以下调用会退出脚本?

Windows 为什么对标签的以下调用会退出脚本?,windows,batch-file,cmd,Windows,Batch File,Cmd,我已经创建了一个标签:checkNetworkDrive来测试一个条件: :checkNetworkDrive setlocal if not exist %drive%\ ( echo The specified drive does not exist exit /b 1 ) exit /b 0 现在,从2个呼叫到此标签的呼叫工作方式不同。对标签1的调用正常工作,即打印存在/不存在,而对标签2的调用退出整个脚本。是否由于标签2中存在setlocal enableDel

我已经创建了一个标签
:checkNetworkDrive
来测试一个条件:

:checkNetworkDrive  
setlocal

if not exist %drive%\ (
    echo The specified drive does not exist
    exit /b 1
)
exit /b 0
现在,从2个呼叫到此标签的呼叫工作方式不同。对标签1的调用正常工作,即打印存在/不存在,而对标签2的调用退出整个脚本。是否由于标签2中存在
setlocal enableDelayedExpansion

标签1: 标签2:
您显示的代码不是问题的原因。也许您还有第二个标签
:checkNetworkDrive
。您是否尝试过退出前是否从label2执行
:checkNetworkDrive
?在函数的开头添加一个
echo CHECKDRIVE“%drive%”
,可能
drive
的内容是邪恶的。我建议您首先从脚本中退一步,决定是否要检查驱动器的存在、可用性,或者特定用户是否可以访问该驱动器。结果可能是,
如果存在
并不是您真正想要的。
set drive=...
call :checkNetworkDrive 
if %errorlevel% == 1 (
    echo "exists"
) else ( 
    echo "not exist"
)
setlocal enableDelayedExpansion
set drive=...
call :checkNetworkDrive 
if %errorlevel% == 1 (
    echo "exists"
) else ( 
    echo "not exist"
)