IMHO the OP have described the problem inaccurately and his question have several details...
I think he wanted to "Getting >nul 2>&1 to work within a doskey macro
when the corresponding doskey command is executed in a batch file
Although the question said that "the following command" (that is a doskey command
) "works perfectly if typed at the command line", that is not true. To be clear, if you execute the following command
at the command line:
Code: Select all
doskey closeall=taskkill /IM "cmd.exe" /f >nul 2>&1
... then, when you later execute the closeall macro
you still see the output text from taskkill.
So in this case, there is no difference on executing the command from the command-line that from a Batch file.
The OP have not clearly separated the doskey command
used to define a macro, from the closeall macro
used to execute the taskkill command.
Anyway, this confusion disappear if you take into account that: "You cannot run a Doskey macro from a batch file". In other words:
- Just the DOSKEY command can be used in a Batch file.
- The CLOSEALL macro can only be used from the keybard, not from a Batch file.