I'm having a problem with what seems like it should be a fairly basic piece of a script.
ECHO !url1! >> !hostsfile! && ECHO Successfully added !url1! to file. || 2>&1>NUL && ECHO Unable to write !url1! to file. && GOTO :FAIL
It's a conditional that tries to write a URL to a given file, and if access to that file is denied, prints an error message. Unfortunately, CMD also generates its own error message, so at the moment, as output, I'm getting the default error "Access denied" followed by my own "Unable to write www.url.com to file."
I've tried without luck to pipe the default error message to NUL, but even with all my reading up on it, my knowledge on how piping works and the syntax for it is still sparse, and I'm not getting anywhere.
Also, as an aside: is there any way to split that line to be more manageable without causing errors?
Trying stuff like:
ECHO !url1! >> !hostsfile! && ECHO Successfully added !url1! to Hosts file.
|| 2>&1>NUL && ECHO Unable to write !url1! to Hosts. && GOTO :FAIL
or
ECHO !url1! >> !hostsfile! && ECHO Successfully added !url1! to Hosts file. ||
2>&1>NUL && ECHO Unable to write !url1! to Hosts. && GOTO :FAIL
...results in "unexpected character" errors.
NB. Exclamation marks are being used for variables because of delayed expansion.