Cautionary note for Win32 users. This isn't restricted to Perl use, but I fell foul of it through Perl, so I'll note it here.

I'm generating filenames of the form "path/to/xyz.ext" programmically. The ".ext" part is constant, and the "xyz" are alpha-numeric. My program would run along fine for a while and then just hang.

After much debugging, the realisation seeped into my conciousness that each time the program hung, the current filename was "path/to/PRN.ext" or "path/to/PrN.ext" or some other combination of "(P|p)(R|r)(N|n)" as the filename.

A long forgotten memory recalled that under DOS, the name "PRN" was a pseudo-handle for the (parallel port?) print device, much like "CON" is a pseudo-handle for the console. I also recalled that these pseudo-handles were defined to be "considered to exists at all levels in the directory structure".

What this piece of legacy crap design means is that any attempt to use "PRN" or "prn" (etc.) as a filename (for output), regardless of it being prefixed with a path, and/or postfixed with an extension will result in a successful open. BUT attempting to write to it will attempt to write to the printer. In my case, where there is no printer attached, the write just hangs. I guess it may eventually time out, but if it does, it takes longer than I have the patience to wait.

As a workaround, pre- or post-fixing the name part with any characters, or switching to "ext.PRN" avoids the problem.

I've long enjoyed the shortness of prog >nul relative to prog >/dev/null, but it has it's downside!


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re: Filenames of "PRN" (or "PrN" etc) on Win32.
by theorbtwo (Prior) on Aug 15, 2004 at 20:56 UTC

    If you're on a copy of windows that has a mem.exe (most seem to, in $windir%\system32 on NTish systems, and %windir%\command on 95ish systems), mem /d will, IIRC, list known device names. I don't, however, have a running windows system to test this on.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      If anyone cares, this the output for me on win2k:
      IO CON AUX PRN CLOCK$ COM1 LPT1 LPT2 LPT3 COM2 COM3 COM4 MSDOS IO KBD HIMEM XMSXXXX0 COMMAND MSDOS COMMAND DOSX MEM MEM MSDOS SYSTEM MSDOS MSCDEXNT DOSX VWIPXSPX MSDOS SYSTEM IO MOUSE REDIR NW16 MSDOS
        Only those under the first IO are relevant:
        CON AUX PRN CLOCK\$ LPT\d+ COM\d+
        There's also NUL, not listed.
        I get this on Win2K SP4:
          Address     Name          Size       Type 
          -------     --------     ------     ------
          000000                   000400     Interrupt Vector
          000400                   000100     ROM Communication Area
          000500                   000200     DOS Communication Area
        
          000700      IO           000370     System Data
                          CON                   System Device Driver 
                          AUX                   System Device Driver 
                          PRN                   System Device Driver 
                          CLOCK$                System Device Driver 
                          COM1                  System Device Driver 
                          LPT1                  System Device Driver 
                          LPT2                  System Device Driver 
                          LPT3                  System Device Driver 
                          COM2                  System Device Driver 
                          COM3                  System Device Driver 
                          COM4                  System Device Driver 
        
          000A70      MSDOS        001670     System Data
        
          0020E0      IO           003120     System Data
                        KBD        000CD0      System Program 
                        ANSI       001060      DEVICE=    
                          CON                   Installed Device Driver 
                        HIMEM      0004E0      DEVICE=    
                          XMSXXXX0              Installed Device Driver 
                                   000490      FILES=     
                                   000090      FCBS=      
                                   0001B0      LASTDRIVE= 
                                   0007D0      STACKS=    
          005210      COMMAND      000A20     Program   
          005C40      MSDOS        000070     -- Free --
          005CC0      COMMAND      000BA0     Environment
          006870      DOSX         0087A0     Program   
          00F020      MEM          000AB0     Environment
          00FAE0      KB16         0017D0     Program   
          0112C0      MEM          017550     Program   
          028820      MSDOS        0777C0     -- Free --
          09FFF0      SYSTEM       02F000     System Program
        
          0CF000      IO           003100     System Data
                        MOUSE      0030F0      System Program 
          0D2110      MSDOS        000AC0     -- Free --
          0D2BE0      MSCDEXNT     0001D0     Program   
          0D2DC0      REDIR        000A70     Program   
          0D3840      DOSX         000080     Data      
          0D38D0      MSDOS        00C720     -- Free --
        
        
            655360 bytes total conventional memory
            655360 bytes available to MS-DOS
            584992 largest executable program size
        
           1048576 bytes total contiguous extended memory
                 0 bytes available contiguous extended memory
            941056 bytes available XMS memory
                   MS-DOS resident in High Memory Area
        
        Oddly, if I don't redirect the output it clears the screen halfway through. Must be generating a spurious character somewhere, which doesn't occur if you > the output.

      Indeed it does (on XP). Thanks, I was unaware of that one.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
Re: Filenames of "PRN" (or "PrN" etc) on Win32.
by gaal (Parson) on Aug 15, 2004 at 17:14 UTC
    Oh, my. This reminds me of the BBS days where the 133t kiddies crashed remote systems by uploading junk with the filename CLOCK$. This was nasty -- it actually overwrote the CMOS!