有关批处理文件,连接字符串等的问题 [英] Questions about batch file, concatenating string and more

查看:87
本文介绍了有关批处理文件,连接字符串等的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我写了一个小批处理文件:

Hello all,
I wrote a small batch 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%"



我有一些问题,如果您能帮助我...

1. case1:我收到以下错误:
错误:"MyTest应用程序"日志不存在.无法创建事件.
通过高级(c#)代码登录初始事件日志的唯一方法?

2. case3:如何将字符串与一些bat变量连接起来?

3. case4:如何在说明中添加换行符?
退出代码:%boolResult%\ n会话ID为%SessionName%"
没有那样做.

感谢您的帮助.



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

1. case1: I get the following error:
ERROR: ''MyTest Application'' log does not exist. Cannot create the event.
The only way to initial eventlog in through high-level (c#) code?

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

3. 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

推荐答案

我已经有一段时间没有使用批处理文件了,但是这是过去的工作方式.

1)如果eventlog仅需要为空白文件,则可以使用重定向到文件名的ECHO创建一个.如果需要某种特殊格式,则需要复制现有文件或使用anotehr方法.

2)通常,只需将%1用作命令行参数,将%varname%用作环境变量,然后批处理程序将%1和%varname%替换为相应的参数字符串.

3)不知道该怎么做.
I haven''t used batch files for awhile, but here''s how it used to work.

1) If eventlog just needs to be a blank file, then you can create one by using ECHO redirected to a file name. If it needs to be some special format, then you''ll need to either copy an existing file or use anotehr method.

2) Usually you just put %1 for commandline parameters and %varname% for environment variables and the batch processor replaces %1 and %varname% with the corresponding parameter string.

3) Not sure how to do that.


这篇关于有关批处理文件,连接字符串等的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆