简体   繁体   English

在使用批处理文件进行静默安装期间,如何阻止窗口退出?

[英]Hopw to stop the window from exiting during silent installation using batch file?

I wrote a batch file which does silent installation which is working fine. 我写了一个批处理文件,它可以进行静默安装,效果很好。 But how do I read the error messages if any appear? 但是,如果出现任何错误消息,我该如何阅读? Can I write all the error/success messages to a log file? 我可以将所有错误/成功消息写入日志文件吗? Also is there any command to stop the window from exiting? 是否有任何命令停止窗口退出?

There's the PAUSE command, which does nothing else then printing a message ( Press any key to continue . . . ) and waiting till a key is pressed. PAUSE命令,该命令什么都不做,然后打印一条消息( Press any key to continue . . . )并等待直到按下某个键。 That would allow you to read any messages before the window goes. 这样一来,您就可以在窗口消失之前阅读所有消息。 Just add the command to the batch file before the end of the script and/or at other position where you need it. 只需在脚本末尾和/或需要的其他位置将命令添加到批处理文件中即可。

You could also try redirecting messages to a file. 您也可以尝试将邮件重定向到文件。 Typically console messages are redirected by adding >filename or 1>filename to the command line. 通常,通过在命令行中添加>filename1>filename来重定向控制台消息。

However, that would only redirect stdout messages, while there might also be stderr ones. 但是,这只会重定向stdout消息,同时可能还会有stderr消息。 Particularly, error messages are often printed to stderr , although that is not a rule and third-party programs may not follow that convention. 特别是,错误消息通常会打印到stderr ,尽管这不是规则,并且第三方程序可能不遵循该约定。 Anyway, stderr messages would need to be redirected with 2>filename put on the command line. 无论如何, stderr消息都需要使用命令行中的2>filename进行重定向。

To redirect both and make sure they go to the same file, use 1>filename 2>&1 on the command line. 要重定向两个文件并确保它们都转到同一文件,请在命令行上使用1>filename 2>&1

You can add the redirection either to specific commands in the script or to the batch file in general. 您可以将重定向添加到脚本中的特定命令或通常添加到批处理文件。 If you redirect specific commands of which there's more than one and you want the results to be logged in the same file, you'll need to use >> instead of > on all or at least all but the first command. 如果您重定向的命令不止一个,并且希望将结果记录在同一文件中,则除了第一个命令之外,所有或至少所有命令都需要使用>>而不是> That's because > would rewrite the output file if it existed and >> would append to it. 这是因为>将重写输出文件(如果存在的话),并将>>添加到该文件之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM