How to escape 2>nul [solved]
Posted: 21 Jan 2013 07:29
How can I Escape the "2>nul" in this Command
My Batch will Create another batch that will have the above command in a For command, I use This:
The 2^>nul is already escaped in the For command "i mean here the > sign", how can i re escabe it again so it will be created in the new batch like this:
I was able to get it to work , but there is 1 extra ^ sign and i can't make them go away.
The rule is % and ^ must be multiplied by 4, so it will be %%%% and ^^^^, but when escaping the > sign the last one from the ^^^^ escape the next ^ sign that should be escaping the > , it did it's work and escaped the > sign but also was written in the new file.
I know i can remove the whole "2^>nul" from the command "and that what i did" but was wondering how this thing can be escaped ... any idea
Code: Select all
TASKLIST /nh /fi "imagename eq cmd.exe" 2>nul
My Batch will Create another batch that will have the above command in a For command, I use This:
Code: Select all
@Echo OFF
(
Echo.@Echo OFF
Echo.SETLOCAL
Echo.FOR /F "tokens=2" %%%%a IN ^('TASKLIST /nh /fi "imagename eq cmd.exe" 2^>nul'^) DO SET Mpid=%%%%a
Echo.Echo %%Mpid%%
Echo.ENDLOCAL
Echo.Pause
)>"new.bat"
The 2^>nul is already escaped in the For command "i mean here the > sign", how can i re escabe it again so it will be created in the new batch like this:
Code: Select all
@Echo OFF
SETLOCAL
FOR /F "tokens=2" %%a IN ('TASKLIST /nh /fi "imagename eq cmd.exe" 2^>nul') DO SET Mpid=%%a
Echo %Mpid%
ENDLOCAL
Pause
I was able to get it to work , but there is 1 extra ^ sign and i can't make them go away.
The rule is % and ^ must be multiplied by 4, so it will be %%%% and ^^^^, but when escaping the > sign the last one from the ^^^^ escape the next ^ sign that should be escaping the > , it did it's work and escaped the > sign but also was written in the new file.
Code: Select all
(
Echo.@Echo OFF
Echo.SETLOCAL
Echo.FOR /F "tokens=2" %%%%a IN ^('TASKLIST /nh /fi "imagename eq cmd.exe" 2^^^^^>nul'^) DO SET pid=%%%%a
Echo.Echo %%pid%%
Echo.ENDLOCAL
)>2nd.bat