Pregunta

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?

¿Fue útil?

Solución

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. 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.

However, that would only redirect stdout messages, while there might also be stderr ones. Particularly, error messages are often printed to stderr, although that is not a rule and third-party programs may not follow that convention. Anyway, stderr messages would need to be redirected with 2>filename put on the command line.

To redirect both and make sure they go to the same file, use 1>filename 2>&1 on the command line.

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top