计算批处理脚本的执行次数
这是我的问题,我有一个无法修改的批处理脚本(我们称之为 foo),我想计算该脚本每天执行的次数 - 以跟踪该数据。
最好,我想将带有日期和退出代码的执行次数写入某种日志文件。
所以我的问题是这是否可能,在这种情况下如何?创建一个批处理脚本/在后台运行的东西并将 foo 的每次执行写入日志。
(我知道如果我可以修改 foo 这会很容易,但我不能。而且,一切都在 WinXP 机器上运行。)
This is my problem, I've got a batch-script that I can't modify (lets call it foo) and I would like to count how many times/day this script is executed - to keep track of that data.
Preferably, I would like to write the number of executions with date and exit-code to some kind of log file.
So my question is if this is possible and in that case - how? To create a batch-script/something that works in the background and writes every execution of foo to a log.
(I know this would be easy if I could modify foo but I can't. Also, everything is running on WinXP machines.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以编写一个包装器脚本来执行日志记录并调用现有脚本。然后使用包装器代替原始脚本
You could write a wrapper script that does the logging and calls the existing script. Then use the wrapper in place of the original script
考虑编写一个询问任务管理器的程序。
请参阅 http://www.netomatix.com/ProcDiagnostics.aspx
例如,您可以编写一个在计时器上运行的简单控制台应用程序;每 5 秒它会检查您的 foo 应用程序进程是否存在。如果发现存在,则假定 find 作为应用程序的启动时间;如果没有找到,它会假设应用程序现已关闭并记录该信息。无论如何,它都不会精确到秒,但会给你一个粗略的近似值,告诉你事物何时运行和关闭。
Consider writing a program that interrogates the Task Manager.
See http://www.netomatix.com/ProcDiagnostics.aspx
You could, for example, write a simple Console app which runs on a timer; every 5 seconds it checks that your foo application process exists. If it finds that it does, it assumes that find as the start time of the application; if it doesn't find it, it assumes the application has now closed and logs that information. It wouldn't be accurate to the second by any means, but would give you a rough approximation of when the thing is running and closing.
您也许可以配置进程监视器
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx 捕获您需要的信息
You might be able to configure Process Monitor
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx to capture the information you require