Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Mock system clock on Windows?

by DrWhy (Chaplain)
on Apr 25, 2007 at 02:08 UTC ( [id://611900]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings Monks,

I'm testing licensing restrictions on a Window application (using a Perl test scripts) and I want to test the behavior when the license expires. The format of the license file (FlexLM) does not allow you to set an expiration time, only an expiration date. The expiration happens at midnight. I want to be able to run the test at any time -- not just midnight. Is there anyway in Perl to mock the system clock so that the application when launched by Perl will see the time I want it to see, rather than the real clock?

Note: This is not a job for Test::MockTime because that only mocks time inside the Perl interpreter itself, not external processes it launches.

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Replies are listed 'Best First'.
Re: Mock system clock on Windows?
by ikegami (Patriarch) on Apr 25, 2007 at 03:10 UTC
    Use "DOS" command time to change the clock, then net time /set to resynchronize the clock?
      This looks like it will work well enough for my purposes, although it really isn't mocking the clock. Actually net time /set doesn't work for our system -- I think because our network doesn't use domain controllers -- or something. What does work for us is
      w32tm /resync
      Thanks!

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Re: Mock system clock on Windows?
by Fletch (Bishop) on Apr 25, 2007 at 03:27 UTC

    On *NIXen you can play games (sometimes) with the shared library linker (ld.so or the like) and shim in your own version of library routines. Perhaps there's some analogue for Win32?

    Another solution might be to use some virtualization package (e.g. VMWare) and set the clock in that to whatever you desire. (although that might be overkill :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2025-03-27 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (70 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.