Hi fellow batches,
I am trying to hide the error output from the Reg Query command, if a registry entry do not exist.
Normally I would just add the command "nul 2>&1" to hide any output the command will give. But if I add this to the first line that generates the error message in case the registry do not exist, then none of the registry entries which was initially found, will be transfered to the output file "del.txt", which is the main purpose of the command.
I would very much like to have a clean batch file, so I hope someone can help me with a way to hide only the error output.
You can see my command underneath:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Code Store Database\Distribution Units" /f "Java Runtime Environment" /s | find "HKEY_LOCAL_MACHINE" > del.txt
for /f "tokens=* delims= " %%a in (del.txt) do reg delete "%%a" /f > nul 2>&1
Regards
Rubl
How-to hide error output from Reg Query command?
Moderator: DosItHelp
Re: How-to hide error output from Reg Query command?
your code works for me, eg. on the command line:No message, no error message. Turn "echo on" to see, what happens.
Code: Select all
for /f "tokens=* delims= " %a in (del.txt) do @reg delete "%a" /f > nul 2>&1
Re: How-to hide error output from Reg Query command?
nono.. it is this line that causes the issue, if the mentioned registry path does not exist:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Code Store Database\Distribution Units" /f "Java Runtime Environment" /s | find "HKEY_LOCAL_MACHINE" > del.txt
The next line is ok, as you also found out.
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Code Store Database\Distribution Units" /f "Java Runtime Environment" /s | find "HKEY_LOCAL_MACHINE" > del.txt
The next line is ok, as you also found out.
Last edited by Rubl7 on 27 May 2013 06:51, edited 1 time in total.
Re: How-to hide error output from Reg Query command?
ok, try this:
Code: Select all
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Code Store Database\Distribution Units" /f "Java Runtime Environment" /s >nul 2>&1 | find "HKEY_LOCAL_MACHINE" > del.txt
Re: How-to hide error output from Reg Query command?
That does hide the error output. But it also does not forward the findings in the Reg Query and paste it into the "del.txt" file. Which means that the "del.txt" file will always be empty
Guess it just dumps the Reg Query findings in a black hole and then create an empty file.
Guess it just dumps the Reg Query findings in a black hole and then create an empty file.
Re: How-to hide error output from Reg Query command?
This seems to hide the STDERR which is all that's needed.
Code: Select all
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Code Store Database\Distribution Units" /f "Java Runtime Environment" /s 2>nul | find "HKEY_LOCAL_MACHINE" > del.txt
Re: How-to hide error output from Reg Query command?
yes, output must to "find", not to "nul" ...
Re: How-to hide error output from Reg Query command?
Brilliant guys.. Thanks