简体   繁体   English

Findstr 批处理在中时不会打开

[英]Findstr batch won't open while in

Been playing around with the findstr within a batch to get an event entry within the Windows as it's older software that doesn't do this on its own accord.一直在批处理中使用 findstr 以获得 Windows 中的事件条目,因为它是较旧的软件,不会自行执行此操作。

Batch opens most recent log file and checks for the word failed writing to the event log if it finds it, this works if the log file is located on my desktop but not if it's the native directory in program data:批处理打开最新的日志文件并检查是否找到了单词 failed writing to the event log,如果日志文件位于我的桌面上,但如果它是程序数据中的本机目录,则无效:

FOR /F "delims=|" %%I IN ('DIR "C:\ProgramData\**supplier**\**application**\Backup\Logs\*.txt" /B /O:D') DO SET NewestFile=%%I

FINDSTR "failed" "%NewestFile%" 
IF NOT ERRORLEVEL 1 EVENTCREATE /T WARNING /ID 963 /L APPLICATION /SO **application Backup** /D "**application** Backup failed"

pause

Thank you in advance.先感谢您。

Update: sorry should have mentioned I've run as admin and also ensured the file in the PD directory isn't in use.更新:抱歉应该提到我已经以管理员身份运行,并确保 PD 目录中的文件没有被使用。 The error I get back is:我回来的错误是:

FINDSTR: Cannot open *.txt

Ended up being a failing with my DIR request, needed the full file path with /S arguement:最终我的 DIR 请求失败,需要带有 /S 参数的完整文件路径:

FOR /F "delims=|" %%I IN ('DIR "C:\ProgramData\**supplier**\**application**\Backup\Logs\*.txt" /B /S /O:D') DO SET NewestFile=%%I

FINDSTR "failed" "%NewestFile%" 
IF NOT ERRORLEVEL 1 EVENTCREATE /T WARNING /ID 963 /L APPLICATION /SO **application Backup** /D "**application** Backup failed"

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

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