Can someone explain to a complete beginner to streams about streams, how to use them, and other quirks?
Streams
Moderator: DosItHelp
Re: Streams
:: --------------------------------------------------------------------------------------------------------------------------
:: - streams
:: --------------------------------------------------------------------------------------------------------------------------
::
:: (
To prevent streams to be disabled "permanently", even for the parent CMD.EXE shell,
streams have to be redirected in a descending order.
1 streams:
>nul
2 streams:
2>nul >&2
3 streams:
3>nul 2>&3 >&2
or individually:
3>nul 2>nul >nul
@echo off & setlocal disableDelayedExpansion
( ( >&2 ( echo.redirecting to stream 2 succesfully ) ) >&3 ) >&2
>&3 ( echo.redirecting to stream 3 succesfully )
( >con ( echo.redirecting con to nul failed ) ) >nul
4< "%~f0" (
>&2 ( echo.redirecting to stream 2 while receiving input succesfully )
>&3 ( echo.redirecting to stream 3 while receiving input succesfully )
<&4 set /P $=
)
echo. "$=%$%_"
pause
exit
--- output ---
redirecting to stream 2 succesfully
redirecting to stream 3 succesfully
redirecting con to nul failed
redirecting to stream 2 while receiving input succesfully
redirecting to stream 3 while receiving input succesfully
"$=@echo off & setlocal disableDelayedExpansion_"
Druk op een toets om door te gaan. . .
3< "%~nx0" (
set "$=" &<&3 set /P "$="
>&4(echo.to disp)
>&5(echo.to file)
) 5> "file.tmp"
Color streams
@echo off & setlocal disableDelayedExpansion
( echo.test | findstr /N /A:2A "^" ) 2>&1 1>&3 | findstr /N /A:4E "^"
( test | findstr /N /A:2A "^" ) 2>&1 1>&3 | findstr /N /A:4E "^"
pause
exit
--- output ---
<green> 1:test
<red> 1:test wordt niet herkend als een interne
2:of externe opdracht, programma of batchbestand.
Druk op een toets om door te gaan. . .
:: )
:: --------------------------------------------------------------------------------------------------------------------------
:: - streams
:: --------------------------------------------------------------------------------------------------------------------------
::
:: (
To prevent streams to be disabled "permanently", even for the parent CMD.EXE shell,
streams have to be redirected in a descending order.
1 streams:
>nul
2 streams:
2>nul >&2
3 streams:
3>nul 2>&3 >&2
or individually:
3>nul 2>nul >nul
@echo off & setlocal disableDelayedExpansion
( ( >&2 ( echo.redirecting to stream 2 succesfully ) ) >&3 ) >&2
>&3 ( echo.redirecting to stream 3 succesfully )
( >con ( echo.redirecting con to nul failed ) ) >nul
4< "%~f0" (
>&2 ( echo.redirecting to stream 2 while receiving input succesfully )
>&3 ( echo.redirecting to stream 3 while receiving input succesfully )
<&4 set /P $=
)
echo. "$=%$%_"
pause
exit
--- output ---
redirecting to stream 2 succesfully
redirecting to stream 3 succesfully
redirecting con to nul failed
redirecting to stream 2 while receiving input succesfully
redirecting to stream 3 while receiving input succesfully
"$=@echo off & setlocal disableDelayedExpansion_"
Druk op een toets om door te gaan. . .
3< "%~nx0" (
set "$=" &<&3 set /P "$="
>&4(echo.to disp)
>&5(echo.to file)
) 5> "file.tmp"
Color streams
@echo off & setlocal disableDelayedExpansion
( echo.test | findstr /N /A:2A "^" ) 2>&1 1>&3 | findstr /N /A:4E "^"
( test | findstr /N /A:2A "^" ) 2>&1 1>&3 | findstr /N /A:4E "^"
pause
exit
--- output ---
<green> 1:test
<red> 1:test wordt niet herkend als een interne
2:of externe opdracht, programma of batchbestand.
Druk op een toets om door te gaan. . .
:: )
:: --------------------------------------------------------------------------------------------------------------------------