Batch Logging New Line

Viewed 43

Pretty simple problem which I am sure the solution is easy, but I simply cannot find the solution anywhere. Please forgive my limited understanding of batch, I am a unix person.

I have a for loop in batch which runs a script on the contents of a user-defined folder. If an error occurs, the script will output a message to the command prompt. I am logging these messages by

"%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% 
)

Now, this logs just fine, but each message is concatenated to the next without a line break. How would I insert a line break such that each message gets its own line?

I have tried:

"%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

All do not produce the desired results. Any ideas?

1 Answers

It seems, that your fooster_io.R doesn't add newlines by itself.
But you can place the "newline" into the for-loop.

"%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(
  )
)

I'm using echo( instead of echo., because it's much faster and it doesn't fail.

Related