Jeremy
Jeremy

Reputation: 69

Suppress command line output but still log

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

Upvotes: 2

Views: 2878

Answers (2)

Mischa
Mischa

Reputation: 1333

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

Upvotes: 2

Hackoo
Hackoo

Reputation: 18827

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

Upvotes: 2

Related Questions