开发者

Concatenate a variable with a string

I wrote a small bat file:

@echo off

rem runs the {arg[0].exe} - using its fully qualified name
%~f1

IF %errorlevel% NEQ 0 
(set boolResult=False) 
ELSE 
(set boolResult=True) 


rem case1 
EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: %errorlevel%; session id is %SessionName%"

rem case3
EVENTCREATE /T ERROR /ID 700 /L APPLICATION /D "exitcode: %boolResult%; session id is %SessionName%"

rem case4 
EVENTCREATE /T ERROR /ID 700 /L APPLICATION /D "exitcode: %errorlevel%; session id is %SessionName%"

And I have got some questions, if you could help me out...

  1. case1: I get the following error:

    ERROR: 'MyTest Application'开发者_如何学JAVA log does not exist. Cannot create the event.

*The only way to initial eventlog in through high-leve (c#) code?

  1. case3: How can I concatenate a string with some bat variable ?

  2. case4: How do I add a newline in the description?

"exitcode: %boolResult%\n session id is %SessionName%"

didn't do that.

Thanks for any assistance


The only way to initial eventlog in through high-leve (c#) code?

This is correct, there is no command line tool to create new event logs. One option here would be to use a PowerShell script and use the System.Diagnostics.Eventlog class.


case3: How can I concatenate a string with some bat variable ?

The way you do is right, so your log entry text

EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: %errorlevel%; session id is %SessionName%"

should expand to:

EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: 0; session id is Console"

case4: How do I add a newline in the description?

You can't. There is no way of providing a newline via command line parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜