简体   繁体   English

记录批处理文件的退出

[英]Logging the exit of a batch file

So I wrote a tool with some batch commands, nothing specific. 所以我写了一个带有批处理命令的工具,没有具体说明。 In the beginning the user can choose which task to perform thanks to a loop. 首先,由于循环,用户可以选择要执行的任务。

In that loop I included the "Q" option, as to quit the batch file. 在该循环中,我包括“ Q”选项,以退出批处理文件。 When this happens, it gets written to a logfile to check when the user started the script(s), and when it ended. 发生这种情况时,它将被写入日志文件,以检查用户何时启动脚本以及脚本何时结束。

The issue is this only happens if the user actually quits/exits with Q. If (s)he quits by just closing the batch file, this won't be logged. 问题是,仅当用户实际退出/退出Q时,才会发生这种情况。如果仅通过关闭批处理文件退出,则不会记录该事件。

In short: how can I record when the user has quit the batch file without using the build-in function? 简而言之:如何记录用户不使用内置功能就退出批处理文件的时间?

a batch file can't receive the "exiting"-event. 批处理文件无法接收“退出”事件。 What you can do is: 您可以做的是:

  1. Make a launcher.bat file, that starts the original (yourfilename).bat file with: 制作launcher.bat文件,该文件使用以下命令启动原始(您的文件名).bat文件:

    start /wait (yourfilename).bat 开始/ wait (您的文件名).bat

  2. the launcher.bat file will now wait until you close the second (yourfilename).bat file. 现在, launcher.bat文件将等待,直到您关闭第二个您的文件名).bat文件。 place your log-information on the next line of launcher.bat 将您的日志信息放在launcher.bat的下一行

  3. convert launcher.bat to launcher.exe using bat to exe converter (and make it invisible ). 使用bat到exe转换launcher.bat转换为launcher.exe (并使它不可见 )。

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

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