changing the system date

Asked by Kris Stanton

I am using sikuli to do some testing and need to change the system date in between tests. Is this possible? I am new to sikuli and python, so maybe I am missing something. I know I can GET the system date, but setting it seems like altogether a different beast. I've found the "SetSystemDate" fuction, but the pywin32 extension isn't easy to integrate with sikuli. Is there another way?

Thanks for your help!

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

This is one of the principal solutions:

import datetime
print datetime.date.today() # for debug only

import os
cmd = r'"echo 08-05-2013 | date"'
os.system(cmd)

print datetime.date.today() # for debug only

Be aware: Sikuli has to be run with admin rights.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

BTW: tested on Win7-32

Revision history for this message
Kris Stanton (kstanton) said :
#3

This is driving me nuts, I tried your above solution and am getting this error (used "commands.getoutput" to see the output it was producing, since it never worked):

'{' is not recognized as an internal or external command, operable program or batch file.

I checked the cmd string that it was passing and it was:
"echo 05-03-2012|date"

(no curly brackets) and I tried different variations, all with the same result. I ran the string on the command line no problem...what am I doing wrong?

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Have you done it exactly as I supposed?

Did you copy and paste it?

just try to type especially the pipe character with your own keyboard and use the raw string format ( r ' text ' )with single apostrophes to be able to have " (apostrophe) inside the command string.

Have spaces around the pipe character.

Revision history for this message
Kris Stanton (kstanton) said :
#5

I didn't copy and paste it but it is exactly as it is with the single quote, then double quote and when showing the string, it shows it with the quotes around it. I also have spaces around the pipe. I tried with with spaces, without spaces, with the quotes, without...they all generate the same error. :(

Revision history for this message
RaiMan (raimund-hocke) said :
#6

I have no idea. a locale problem?

So this is another chance:

make a setdate.cmd somewhere with the content:

echo %1 | date

and in the script use
cmd = r"absolute-path-to-setdate.cmd 05-03-2012"

Still to be run as admin.

Can you help with this problem?

Provide an answer of your own, or ask Kris Stanton for more information if necessary.

To post a message you must log in.