1

I am trying to write a command-line script that will be triggered each time an event log in a specific Windows Event Log is logged. Here's what I have so far:

wevtutil qe WebsitePanel "/q:*" /f:text /rd:true /c:1 > %tmp%\WebsitePanelErrorLog.log

set var1 = < %tmp%\ErrorLog.log

C:\bmail.exe -s aspmx.l.google.com -t [email protected] -f [email protected] -a "wh00: WebsitePanel Event Logged" -b %var1%

del %tmp%\WebsitePanelErrorLog.log

The problem is var1 is not being set for some reason. If I do this, it just returns empty:

echo %var1%

Any ideas?

2
  • If I understand you correctly, you're trying to write a batch script that will react to changes in a file. As far as I know, this is not possible in Windows. Commented Jan 15, 2011 at 18:21
  • No, the batch file is called each time an event is triggered... I want to take the output of the "wevtutil" command and use it as a parameter for bmail.exe Commented Jan 16, 2011 at 1:16

1 Answer 1

2

The set command does not take input from stdin. Instead of redirection try something like

for /f %x in ('type %tmp%\ErrorLog.log') do set var1=%x
Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't work. All this does is assign %var1% to be the first word on the last line.
I said something like this. You want to add "delims=" after the /f to get full lines. Also look at "help set" to see how to use delayed expansion in order to collect all the lines in the file. Finally do not forget to convert % to %% when used inside a batch file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.