catch CONOUT$ in For / F ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

catch CONOUT$ in For / F ?

#1 Post by carlos » 08 Nov 2013 09:25

Please, If I execute a command that write to CONOUT$ file the contents is printed in screen, but there a way of catch this in for /f ?

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: catch CONOUT$ in For / F ?

#2 Post by carlos » 08 Nov 2013 10:35

I tried for example using makecab use as inf file the CONOUT$
I redirect to NUL but it anyways print.

code based in my getDate function: http://www.dostips.com/forum/viewtopic.php?p=29758#p29758

I need redirect CONOUT$ to CON for catch the content with For /F

Code: Select all

@Echo Off

Call :Init
Call :Test
Goto :Eof

:Init
(
Echo .Set InfHeader=""
Echo .Set InfSectionOrder=""
Echo .Set InfFooter="%%2"
Echo .Set InfFooter1=""
Echo .Set InfFooter2=""
Echo .Set InfFooter3=""
Echo .Set InfFooter4=""
Echo .Set Cabinet="OFF"
Echo .Set Compress="OFF"
Echo .Set DoNotCopyFiles="ON"
Echo .Set RptFileName="NUL"
Echo .Set InfFileName="CONOUT$"
) >"%Temp%\~foo.ddf"
Goto :Eof

:Test
Makecab /F "%Temp%\~foo.ddf" >NUL
Pause

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

Re: catch CONOUT$ in For / F ?

#3 Post by Aacini » 08 Nov 2013 10:52

CON is the name of the console driver. I tested redirecting to CONOUT and it works OK. However, redirecting to CONOUT$ redirects to the console again. I can only suppose that the $ at end is a marker for device driver names (I think I read something about this point long time ago). If this is true, then there is no way to use CONOUT$ as a file name... :(

Antonio

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: catch CONOUT$ in For / F ?

#4 Post by aGerman » 08 Nov 2013 12:21

I don't see the context to a FOR /F :?
You could use the behaviour of Windows that doesn't allow trailing spaces in a file name but outomatically removes them instead.

Code: Select all

>CONOUT$^  echo Hello world!

It's only a workaround but it doesn't explain why CONOUT works while CONOUT$ does not. Currently I have no idea ...

Regards
aGerman

jeb
Expert
Posts: 1062
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: catch CONOUT$ in For / F ?

#5 Post by jeb » 08 Nov 2013 16:38

There is a really simple explanation at microsoft: 8)

INFO: CreateFile() Using CONOUT$ or CONIN$

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: catch CONOUT$ in For / F ?

#6 Post by aGerman » 08 Nov 2013 18:46

How could I miss that. I use CreateFile for a long time but was never aware of these stream keywords.

Post Reply