Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Win32::EventLog's clear method without filename.

by dannyd (Sexton)
on Dec 16, 2010 at 10:40 UTC ( [id://877467]=perlquestion: print w/replies, xml ) Need Help??

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

Monks, Namaste,

Ive just started using perl and am trying to use the Win32::EventLog module's clear method to clear a log without having to save it to a file(When I passed filename, it saved and then cleared the log sucessfully).

i've tried, [found a thread with this in it, dont really know what that does]$Event->Clear(undef);$Event->Clear(); $Event->Clear(""); and $Event->Clear('');

but none of them work.

Please help!!

Replies are listed 'Best First'.
Re: Win32::EventLog's clear method without filename.
by dasgar (Priest) on Dec 16, 2010 at 15:51 UTC

    After looking at the documentation for Win32::EventLog and looking into the contents of it's .pm file on my system, I believe that the Clear function is expecting a file name of a new file to create.

    If you're not wanting to keep the log contents, you can let the Clear function dump to a temporary file and then delete the temp file. I haven't used it myself, but File::Temp might help make it easier to do that.

Re: Win32::EventLog's clear method without filename.
by Marshall (Canon) on Dec 16, 2010 at 21:38 UTC
    I haven't used Win32::EventLog, but from your description, I think what is needed is the "bit bucket". On Windows there is a special reserved file name, "nul". This file is special. Anything written to the file called "nul" is discarded - it just goes away.

    The name nul, will not appear in any directory listing as this file cannot exist. You can however open a filehandle to nul to "create it", write to it and close it. It will all look like a normal file operation except at the end of the day, a file called nul is never actually created. On Windows, case doesn't matter, NUL and nul are the same. The path doesn't matter. You can write to nul in any directory.

    C:\Projects>type temp.txt #types temp.txt to stdout C:\Projects>type temp.txt >nul #no output! types temp.text into cyber +space
    There are all sorts of handy uses for nul. Another example:
    C:\someprog.pl 2>nul
    exectues someprog.pl and the normal stdout output is thrown away. But anything written to stderr, like a warning or whatever will appear on the terminal.

    In Unix, this concept is implemented via the device called null. /dev/null. Please note the spelling, and the number of letter l's! That is of course important!

      Thanks a lot dasagar, im using that work around now, script is running fine :).

      Marahal, I tried what you recommended, "nul", "NUL", "NULL" and "null" - none of them work(That would be a nice solution though)

        $Event->Clear(), did you try 'C:\nul'? or some other path that you have write access to, terminating in a file that is not a file, called nul? Puzzled why that didn't work. If you just have 'nul', that would be the directory that the Perl is executing in or maybe the directory that it was launched from. Well in any event, you got a solution. Horray! nul is the right path under Windows for the bit bucket. I'm sure. Flabbergasted why it didn't work for you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-24 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found