Menu

Problem printing to "con"

Help
hodjpodj
2008-10-27
2012-07-26
  • hodjpodj

    hodjpodj - 2008-10-27

    The following code...

    BEGIN {print "test" > "con.txt"}

    ... prints to screen and not to a "con.txt" file as I would expect. This occurs with any path that contains a base file name of "con". I'm guessing there's some sort of redirect to the "console" happening here.

    I've reproduced the problem on Windows XP and Vista, and with Gawk 3.1.2 (cygwin) and 3.1.6 (SourceForge).

    Can others reproduce this? Given I need the base file name to be "con", is there a fix or workaround for this?

     
    • GnuWin

      GnuWin - 2008-10-27

      On MS-Windows names such as aux, com, con, and prn, are reserved device names; see http://msdn.microsoft.com/en-us/library/aa365247.aspx. You cannot use them for as the base part of an ordinary filename.

       
      • hodjpodj

        hodjpodj - 2008-10-27

        I'm surprised to learn that Windows redirects such base file names even when a path and/or file name extension is specified. Seems odd. Oh well, I'll add some special cases to my code. Thanks for clearing this up for me.

        As per the link you provided, and for others who are reading this and may not be aware, the Windows/DOS base file names to avoid are: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 (uppercase or lowercase).

         
MongoDB Logo MongoDB