Streams

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sylau
Posts: 4
Joined: 06 Jan 2015 16:23

Streams

#1 Post by sylau » 13 Jun 2015 16:01

Can someone explain to a complete beginner to streams about streams, how to use them, and other quirks?

:D

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Streams

#2 Post by Ed Dyreen » 13 Jun 2015 17:45

:: --------------------------------------------------------------------------------------------------------------------------
:: - 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. . .

:: )
:: --------------------------------------------------------------------------------------------------------------------------

Post Reply