1

I'm trying to suppress output (errors mostly) in the command prompt, but still log all other output in a logfile.

Here I found to suppress it in the cmd line output: Suppress command line output

But how can I do that, while in the mean time all other output will be logged? (to C:\log.txt for example)

Thank you

Community
  • 1
  • 1
Jeremy
  • 59
  • 1
  • 1
  • 11

2 Answers2

2

There are the two parts >nul and 2>&1 in the example provided by you.

>nul redirects the output of the script (stdout) to nul

2>&1 redirects the errors (errout) to the default output

If you write command >nul 2>&1 then errout wil get redirected to stdout and stdout will get redirected to nul

If you want to only log the normal output but not the errors use this

command >logfile.txt 2>nul
Mischa
  • 1,303
  • 12
  • 24
2

This code can log only the success actions into file log.txt

and all errors are redirected to nul :

@echo off
set process=Test.exe,test2.exe,calc.exe,skype.exe
For %%a in (%process%) Do Call :KillMyProcess %%a
pause
Exit /b

:KillMyProcess
Taskkill /IM "%~1" /F >> log.txt 2>nul
Hackoo
  • 18,337
  • 3
  • 40
  • 70