windows - 从 Windows 批处理部分意外退出

标签 windows batch-file

我正在开发一个批处理文件来收集 websphere 产品信息,除了某些情况外,它似乎工作正常。

由于某些原因,在某些情况下会调用 versionInfo.bat -maintenancePackages,但以下代码(检查 manageprofiles.bat)似乎是在调用 versionInfo 后从 :check 部分返回。

我的Windows批处理技巧很生疏,欢迎其他改进。

@echo off
SetLocal EnableDelayedExpansion

set tmpfile=%TEMP%\tmpdone.txt

echo. > %tmpfile%
For /F "eol= delims=| tokens=13" %%a in (%windir%\vpd.properties) Do (
set check=%%a
call :check
)
goto eof

:check
Set skip=No
For /F "eol= delims=|" %%a in (%tmpfile%) Do (
if "%%a" == "%check%" set skip=YES
)

if %skip% == YES goto eof
echo %check%>>%tmpfile%
if exist "%check%\bin\versionInfo.bat" "%check%\bin\versionInfo.bat" -maintenancePackages
echo %check%\bin\manageprofiles.bat
if exist "%check%\bin\manageprofiles.bat" "%check%\bin\manageprofiles.bat" -listProfiles
goto eof

:del
echo Done
del %tmpfile%

:eof

最佳答案

您需要使用call 从另一个批处理文件运行批处理文件。否则 cmd 不会从被调用的返回。所以你的代码应该是:

if exist "%check%\bin\versionInfo.bat" call "%check%\bin\versionInfo.bat" -maintenancePackages
echo %check%\bin\manageprofiles.bat
if exist "%check%\bin\manageprofiles.bat" call "%check%\bin\manageprofiles.bat" -listProfiles
goto :eof

(也不需要:eof跳转标签,直接用goto :eof特殊语法直接退出批处理文件即可,我一般只用这种一个跳转标签,如果我需要先做一些清理,但我会用不同的方式命名它,以避免混淆 :-))

关于windows - 从 Windows 批处理部分意外退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3671943/

相关文章:

batch-file - 如何在 Batch/CMD 中使用 PSLIST 和 FIND 查找精确匹配

python 3.3 : Unable to load an image using Pygame if game folder is not in C drive

c++ - Windows 上的 std::map::operator[] 违规访问内存

c++ - Window Programming (C++) : How to check if child window ID is occupied? 以及如何为子窗口生成唯一ID?

linux - 在 Windows 中从 Linux Samba CVSROOT check out CVS

linux - 使用 Plink 将批处理文件中的多个参数传递给远程 shell 脚本时出现问题

php - 在新命令提示符下执行命令

batch-file - 以管理员身份从另一个批处理文件运行一个批处理文件

windows - 批处理文件调用在 for 循环中转义重定向

batch-file - 使用批处理脚本删除子文件夹中的文件