Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Usage of File::Spec->devnull() on Windows

by chazubell (Beadle)
on Jul 30, 2012 at 16:12 UTC ( [id://984472]=perlquestion: print w/replies, xml ) Need Help??

chazubell has asked for the wisdom of the Perl Monks concerning the following question:

I was attempting to use the following code from Archive:Zip examples on Windows:
# Example of how to compute compressed sizes # $Revision: 1.2 $ use strict; use Archive::Zip qw(:ERROR_CODES); require File::Spec::Win32; my $zip = Archive::Zip->new(); my $blackHoleDevice = File::Spec::Win32->devnull(); $zip->addFile($_) foreach (<*.pl>); # Write and throw the data away. # after members are written, the writeOffset will be set # to the compressed size. $zip->writeToFileNamed($blackHoleDevice); my $totalSize = 0; my $totalCompressedSize = 0; foreach my $member ($zip->members()) { $totalSize += $member->uncompressedSize; $totalCompressedSize += $member->_writeOffset; print "Member ", $member->externalFileName, " size=", $member->uncompressedSize, ", writeOffset=", $member->_writeOffset, ", compressed=", $member->compressedSize, "\n"; } print "Total Size=", $totalSize, ", total compressed=", $totalCompress +edSize, "\n"; $zip->writeToFileNamed('test.zip');
However, while it worked on Linux, OSX, it was a failure on Windows. BTW: while stepping through the debugger i saw that the scalar $blackHoleDevice was set to 'nul' not the usual Windows /dev/null device 'NUL'. However even it it was then set to 'NUL' it still did not work. When $blackHoleDevice was replaced by an actual file name it worked fine, but one assumes that the use of /dev/null was used to avoid the actual creation of a file. Question: is this just windows or me?

Replies are listed 'Best First'.
Re: Usage of File::Spec->devnull() on Windows
by tobyink (Canon) on Jul 30, 2012 at 16:27 UTC

    Hmmm... interesting.

    Sorry I don't have the answer, but I can offer a workaround. Archive::Zip supports writeToFileHandle as an alternative to writeToFileNamed. You can probably pass it something other than a real filehandle, like maybe an IO::Null object.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Thanks. To all. I will try writing to a file handle.
Re: Usage of File::Spec->devnull() on Windows
by chazubell (Beadle) on Jul 30, 2012 at 16:25 UTC
    I just found my own answer. The /dev/null device on windows is now NIL OOPS.
      The /dev/null device on windows is now NIL

      That is not true.

      The nul device on wihdows is any file with a name that (without any extension) equals 'nul' in any case.

      Ie nul, NUL nUl, Nul; NUL.TXT, nul.TXT, NUl.tXt, nul.exe, .\nul, .\..\cwd\fred\..\nul.asmanycharactersafterthedotasyoucaretoadd

      C:\test>md newdir C:\test>cd newdir C:\test\newdir>echo . > NIL C:\test\newdir>dir 30/07/2012 21:06 <DIR> . 30/07/2012 21:06 <DIR> .. 30/07/2012 21:06 4 NIL 1 File(s) 4 bytes 2 Dir(s) 101,782,999,040 bytes free C:\test\newdir>echo . > NUL C:\test\newdir>echo . > nul C:\test\newdir>echo . > NuL C:\test\newdir>echo . > ./../newdir/nul C:\test\newdir>echo . > nulpoint C:\test\newdir>echo . > nul.txt C:\test\newdir>echo . > nul.exe C:\test\newdir>echo . > c:\test\newdir\nul.1231243345345 C:\test\newdir>dir Volume in drive C has no label. Volume Serial Number is 8C78-4B42 Directory of C:\test\newdir 30/07/2012 21:07 <DIR> . 30/07/2012 21:07 <DIR> .. 30/07/2012 21:06 4 NIL 30/07/2012 21:07 4 nulpoint 2 File(s) 8 bytes 2 Dir(s) 101,783,220,224 bytes free

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

      Do you have a reference for that? I am not able to verify that this is the case. If it is, ouch (unnecessary backward compatible breakage). In fact, my testing from a Windows 7 cmd prompt and perl script seem to disprove your assertion.

      --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://984472]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-03-19 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found