【问题标题】:Batch Logging New Line批量记录新行
【发布时间】:2021-05-21 03:10:27
【问题描述】:

非常简单的问题,我确信解决方案很简单,但我根本无法在任何地方找到解决方案。请原谅我对批处理的有限理解,我是一个unix人。

我有一个批处理的for 循环,它在用户定义的文件夹的内容上运行一个脚本。如果发生错误,脚本将向命令提示符输出一条消息。我正在通过

记录这些消息
"%UserProfile%\Documents\Fooster\Logs\failed_log.txt" 2>&1  (
for /f %%f in ('dir /s/b %arg1%') do call R-Portable\App\R-Portable\bin\Rscript.exe Scripts\fooster_io.R %%f %arg2% 
)

现在,这个日志很好,但是每条消息都连接到下一条,没有换行符。如何插入换行符以使每条消息都有自己的行?

我试过了:

"%UserProfile%\Documents\Fooster\Logs\failed_log.txt" 2>&1/n
"%UserProfile%\Documents\Fooster\Logs\failed_log.txt" 2>&1 /n
"%UserProfile%\Documents\Fooster\Logs\failed_log.txt" 2>&1 echo.
"%UserProfile%\Documents\Fooster\Logs\failed_log.txt" echo. 2>&1

所有都没有产生预期的结果。有什么想法吗?

【问题讨论】:

    标签: batch-file logging stdout stderr


    【解决方案1】:

    看来,您的 fooster_io.R 本身并没有添加换行符。
    但是您可以将“换行符”放入 for 循环中。

    "%UserProfile%\Documents\Fooster\Logs\failed_log.txt" 2>&1  (
      for /f %%f in ('dir /s/b %arg1%') do (
        R-Portable\App\R-Portable\bin\Rscript.exe Scripts\fooster_io.R %%f %arg2% 
        echo(
      )
    )
    

    我使用echo( 而不是echo.,因为它更快而且不会失败。

    【讨论】:

      猜你喜欢
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 2019-06-19
      • 2019-01-02
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多