我可能做错了。这是我想要做的:
打开一个批处理文件(标记为:run office install.bat)iv'e created。
调用安装批处理文件(标记为:install.bat)并针对它设置错误报告(当前使用与通常使用的批处理文件不同的批处理文件,如 它安装了办公室2013所以只是复制并重命名另一个球棒 同样的测试)。我知道这个批处理文件可以独立工作 使用GOTO:EOF和EXIT / B它应输出错误代码0或> 1
根据返回的错误代码显示错误消息说明 安装失败或显示一条消息,显示安装是一个 成功并删除安装包。
以下是代码:
运行office install.bat
CD "C:\source\Microsoft_Office_2013_01"
CALL install.bat 2> InstallCommand.err
FOR /F "usebackq" %%A IN ('InstallCommand.err') DO set size=%%~zA
IF NOT "%size%"=="0" (
ECHO Error installing MS Office 2013. Please check the log files.
TYPE InstallCommand.err
GOTO:EOF
)
IF "%size%"=="0" (
ECHO MS Office 2013 installed, now deleting install folders...
TYPE InstallCommand.err
RMDIR /s /q "C:\source\Microsoft_Office_2013_01" 2> delCmd.err
OR /F "usebackq" %%A IN ('delCmd.err') DO set size=%%~zA
if not "%size%"=="0" (
ECHO Error deleting install folders
TYPE delCmd.err
)
IF "%size%"=="0" (
ECHO install folders deleted successfully
TYPE delCmd.err
)
)
PAUSE
EXIT
INSTALL.BAT
@ECHO OFF
:delete
ECHO Deleting OffScrub10.vbs
CD c:\temp
DEL /f /q c:\temp\OffScrub10.vbs 2> delCmd.err
FOR /F "usebackq" %%A IN ('delCmd.err') DO set size=%%~zA
IF NOT "%size%"=="0" (
ECHO Error deleting OffScrub10.vbs
TYPE delCmd.err
GOTO :EOF
)
IF "%size%"=="0" (
ECHO OffScrub10.vbs deleted successfully
TYPE delCmd.err
)
PAUSE
EXIT /B
非常感谢任何帮助。
答案 0 :(得分:0)
以下是两个文件的修改版本。我试图让它们与您发布的内容类似,以便您仍然可以关注它们:
运行office install.bat
@ECHO OFF
IF /I NOT "%__CD__%"=="C:\source\Microsoft_Office_2013_01\" (
PUSHD "C:\source\Microsoft_Office_2013_01" 2>NUL||EXIT/B)
CALL "install.bat" 1>NUL 2>"%TEMP%\InstallCommand.err"
FOR %%A IN ("%TEMP%\InstallCommand.err") DO SET "size=%%~zA"
IF %size% NEQ 0 (
ECHO= Error installing MS Office 2013. Please check the log files.
TYPE "%TEMP%\InstallCommand.err"
) ELSE (
ECHO= MS Office 2013 installed, now deleting install folders...
PUSHD "%TEMP%"
RD /S /Q "C:\source\Microsoft_Office_2013_01" 1>NUL 2>"delCmd.err"
FOR %%A IN ("delCmd.err") DO SET "size=%%~zA"
IF %size% NEQ 0 (ECHO= Error deleting install folders
TYPE "delCmd.err") ELSE (ECHO= install folders deleted successfully)
)
TIMEOUT -1
EXIT /B
<强> INSTALL.BAT 强>
@ECHO OFF
IF /I NOT "%__CD__%"=="C:\temp\" (PUSHD "C:\temp" 2>NUL||EXIT/B) ELSE (SET "_=T")
ECHO= Deleting OffScrub10.vbs
DEL /A /F "OffScrub10.vbs" 1>NUL 2>"%TEMP%\delCmd.err"
FOR %%A IN ("%TEMP%\delCmd.err") DO SET "size=%%~zA"
IF %size% NEQ 0 (ECHO= Error deleting OffScrub10.vbs
TYPE "%TEMP%\delCmd.err") ELSE (ECHO= OffScrub10.vbs deleted successfully)
TIMEOUT -1
IF NOT DEFINED _ POPD
EXIT /B
您还需要注意,run office install.bat
无法从C:\source\Microsoft_Office_2013_01
运行,否则您将在其仍在运行时尝试将其删除