你怎么有一个被叫bat文件而不是杀掉它的bat文件?

时间:2009-06-16 17:17:02

标签: windows batch-file

我在Windows 2003系统上,需要在WebSphere Application Server中编写删除和创建配置文件的脚本。这需要我两次调用manageprofiles.bat,一次删除现有配置文件,一次创建新配置文件。

在我的批处理文件中,我有以下内容:

cd "C:\Program Files\IBM\WebSphere\AppServer\bin"
manageprofiles.bat -delete -profileName AppSrv01
rmdir /s /q ..\profiles\AppSrv01
manageprofiles.bat -create -templatePath ..\profileTemplates\default -profileName AppSrv01 -profilePath ..\profiles\AppSrv01

manageprofiles.bat文件以:

结尾
set RC=%ERRORLEVEL%
@endlocal & exit /b %RC%

如果在我的批处理文件的第二行删除配置文件时出错(这种情况经常发生),manageprofiles.bat会发出错误消息并导致我的批处理文件终止。我不希望发生这种情况,因为我将在下一个命令中删除配置文件的其余部分。阅读退出文档会让我相信manageprofiles.bat中exit命令中的/ b应该导致manageprofiles.bat终止而不会影响我的bat文件。

我不想以任何方式触摸manageprofiles.bat文件,因为我的更改可能会被更新恢复,并再次破坏我的脚本。我可以在批处理文件中做些什么来解决这个问题吗?

2 个答案:

答案 0 :(得分:8)

将“manageprofiles.bat”的两次出现更改为“call manageprofiles.bat”。如果没有“调用”,执行将转移到manageprofiles.bat文件,但不会返回。

答案 1 :(得分:4)

使用

 call manageprofiles.bat

有什么不同吗?