【问题标题】:Adding newline in the eventcreate description message while executing from java从 java 执行时在 eventcreate 描述消息中添加换行符
【发布时间】:2015-10-19 05:43:45
【问题描述】:

我们正在尝试通过从 java 执行以下命令来创建 Windows 事件日志。 但无法在描述(/d)中添加换行符(\n)。

eventcreate /t error /id 100 /l myApp /SO "mysource" /d "这是日志的第一行 \n 这是第二行"

从java代码上面执行:Runtime.getRuntime().exec(command);

1.尝试添加 crl+l (^L) 而不是 \n 但它仅适用于命令行而不适用于 java 代码。

【问题讨论】:

    标签: java windows newline event-log stringescapeutils


    【解决方案1】:

    终于找到解决办法了:

    我们可以传递字符串数组,而不是将字符串作为参数传递给 .exec() 方法。这样,日志消息将 \n 标识为新行。下面的代码 sn-p 现在可以工作了。

    String[] command = {"eventcreate", "/t", "error", "/id","100","/l", "CustomApp", "/SO","CustomSource","/d","this is 1st line of the log \n this is second line"};       
    Runtime.getRuntime().exec(command);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-10
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多