can't write stream 3 when receiving input stream

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

can't write stream 3 when receiving input stream

#1 Post by Ed Dyreen » 27 Nov 2013 10:46

What a bummer, I was hoping to use stream 3 for warn/debug messages. :(

Code: Select all

@echo off & setlocal disableDelayedExpansion

   >&2 ( echo.redirecting to stream 2 succesfully )
   >&3 ( echo.redirecting to stream 3 succesfully )

< "%~f0" (

   >&2 ( echo.redirecting to stream 2 while receiving input succesfully )
   >&3 ( echo.redirecting to stream 3 while receiving input failed :^( )
)

pause
exit

Code: Select all

redirecting to stream 2 succesfully
redirecting to stream 3 succesfully
redirecting to stream 2 while receiving input succesfully
Het systeem kan niet naar het opgegeven apparaat schrijven.
Druk op een toets om door te gaan. . .
the error states; 'failed to write to given device'

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: can't write stream 3 when receiving input stream

#2 Post by Aacini » 27 Nov 2013 11:29

Why not just use CONsole device?

Code: Select all

@echo off & setlocal disableDelayedExpansion

   >&2 ( echo.redirecting to stream 2 succesfully )
   >CON ( echo.redirecting to CONSOLE succesfully )

< "%~f0" (

   >&2 ( echo.redirecting to stream 2 while receiving input succesfully )
   >CON ( echo.redirecting to CONSOLE while receiving input succesfully )
)

pause
exit


Antonio

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

Re: can't write stream 3 when receiving input stream

#3 Post by Ed Dyreen » 27 Nov 2013 11:46

con is a device, not a stream, redirecting a device to another stream or device seams impossible. con output ends up on the console always, unlike streams which can be redirected to other streams over and over again.

Code: Select all

@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

< "%~f0" (

   >&2 ( echo.redirecting to stream 2 while receiving input succesfully )
   >&3 ( echo.redirecting to stream 3 while receiving input failed :^( )
)

pause
exit

Code: Select all

redirecting to stream 2 succesfully
redirecting to stream 3 succesfully
redirecting con to nul failed
redirecting to stream 2 while receiving input succesfully
Het systeem kan niet naar het opgegeven apparaat schrijven.
Druk op een toets om door te gaan. . .

All streams end up on one or another device eventually.
stream 1 is usually used for normal output.
stream 2 is usually used for error messages.
stream 3 would be used for warnings, but this doesn't seam to work when an input stream is present.

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

Re: can't write stream 3 when receiving input stream

#4 Post by Ed Dyreen » 27 Nov 2013 12:03

Anyways I think I figure it out :D

Code: Select all

@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

Code: Select all

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. . .
but why :roll:

Anyways, you know you can redirect output from a function right.
That allows to quickly enable more details without having to dive into it eg;

Code: Select all

( %myFunction% arg1, arg 2 ) 3>nul

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: can't write stream 3 when receiving input stream

#5 Post by Aacini » 27 Nov 2013 16:43

I suggest you to read my last post on the thread about this topic...

Antonio

Post Reply