Q: How to suppress error message "permission denied" output on redirecting text into a write-protected file for some users? I have the problem that my batch is on a network drive and not all people have write permission to this path. Normally the batch logs also some information.
I would like to suppress the permission denied info in case of no write permission. My assumption is that I have to redirect the standard error to nul.
But this example is not working. I will get a permission denied. It's OK if the log is not created, but I don't want to see a permission denied error message. This error message should be redirected to stderr.
echo test 1> c:\Windows\log.txt 2> nul


A: If you use the syntax 
echo data >log.txt 2>nul 

you are requesting to send the output generated by the echo command to the log file and the errors generated by the command to nul.
Your problem is that the output to stderr is not generated by the execution of the echo command, but from a failure in the redirection handling rutines that are executed before the echo itself.
You need to move the stderr redirection operation one level up
2>nul ( >log.txt echo data )

Now, the stderr redirection wraps everything inside the parenthesis, that is, the redirection operation and the echo execution.

A: The command line
echo test > c:\Windows\log.txt 2> nul

redirects standard output of command ECHO to file c:\Windows\log.txt and the standard error output of command ECHO to device NUL.
So test with the space before redirection operator > is written to c:\Windows\log.txt which usually does not work because this directory is write-protected and used here as an example for the network folder with individual access permissions.
The command ECHO does never output something to handle STDERR. Therefore the redirection of standard error output of command ECHO to device NUL has never any effect.
What you really want is suppressing the error output of cmd on redirection of ECHO output to the file log.txt in perhaps protected folder which requires a different syntax.
You could use:
(>"%SystemRoot%\log.txt" echo test) 2>nul

Or easier to read:
@echo off
(
    >"%SystemRoot%\log.txt" echo test
) 2>nul

The ECHO command line is enclosed in a command block starting with opening parenthesis ( and ending with matching closing parenthesis ). Everything output by any command in this command block to handle STDERR is redirected to device NUL which includes the error message output by cmd if the current user has no permission to create file log.txt in output directory, or if the output file exists already and has read-only attribute set, or if the output file is opened currently by an application which opened it with a file sharing write lock for other applications.
The redirection operator > and the file name is specified on ECHO command line at beginning to be able to output also a text with number 1 ... 9 at end without writing a trailing space into the file %SystemRoot%\log.txt.
As a command block is used around ECHO command line, the output of a closing round bracket ) by ECHO requires now escaping this character with caret character ^ as demonstrated in example below:
@echo off
(
    >"%SystemRoot%\log.txt" echo '(' and '^)' are round brackets/parentheses.
) 2>nul

A slower alternate solution is using delayed expansion:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "TextToOutput='(' and ')' are round brackets/parentheses. '!' is an exclamation mark."
setlocal EnableDelayedExpansion
(
    echo !TextToOutput!>%SystemRoot%\log.txt
) 2>nul
endlocal
endlocal

%SystemRoot% is replaced already by C:\Windows (or whatever is the path to Windows directory) on parsing the entire command block by Windows command interpreter before executing the first line within ( ... ). But the value of environment variable TextToOutput is not replacing !TextToOutput! before ECHO is executed making it safe now to specify the redirection operator at end without a space before to avoid a trailing space in file on output line.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.


*

*cmd /?

*echo /?

*endlocal /?

*set /?

*setlocal /?
And read also the Microsoft TechNet article Using command redirection operators.

It is also possible to use a completely different technique.
The batch file first redirects everything to a temporary file in folder for temporary files of current user. When finished the temporary log file is copied to network folder or appended to network folder with suppressing the error message if the user has no write permission on network folder.
Example code for usage of this technique:
@echo off
set "LogFile=%TEMP%\%~n0.tmp"
del "%LogFile%" 2>nul

>>"%LogFile%" echo test
rem Other commands with output also redirected to log file.

if exist "%LogFile%" (
    rem copy "%LogFile%" "%~dp0log.txt"
    copy /B "%~dp0log.txt"+"%LogFile%" "%~dp0log.txt"
    del "%LogFile%"
) >nul 2>&1
set "LogFile="

The first COPY command line commented out in batch code above overwrites the log file in directory of the batch file with the newly created log file.
The second COPY command line appends the newly created log file to already existing log file in directory of the batch file.

A: A digit directly before a redirector redirects that-number device.
1 is standard output, so you are trying to redirect the echo output to c:\windows - probably protected and also a directory, not a file.
If your purpose (you don't say) is to redirect test 1 then
 1>file echo test 1 2>nul

but since you don't say explicitly what you want to do, that's a guess.
