Changing the system time on Daylight Saving

We are running v7.3.9 with Java 1.7.0_25 and our vendor left us with a script which is supposed to change the system clock on Daylight Saving days. It uses:

import os
cmd = "time 01:00"
os.system(cmd)

However, this script fails to run. When I try to run it in the Script Tester I get a javaos.py error:

[color=#BF0000]OSError: (0, ‘Failed to execute command ([‘sh’, ‘-c’, ‘time 01:00’]): java.io.IOException: Cannot run program “sh”: CreateProcess error=2, The system cannot find the file specified’)[/color]

I opened [color=#BF0000]javaos.py[/color] and noticed that it is doing a Operating System check to decide what shell command to use, with ‘[color=#BF0000]sh -c[/color]’ being the default. Our servers OS is ‘[color=#BF0000]Windows Server 2008 R2[/color]’ which is not on the list of OS types. I found forums where other were successful in adding ‘Windows Server 2008 R2’ to the list, however, when I change javaos.py it does not seem to change the outcome. Is there a way to fix javaos.py or is there a better way to change the system time?

Doesn’t WinServer auto adjust for DST by default? :open_mouth:

That being said, create a file called C:\DST.BAT (on the gateway) and put this in it:

time 01:00

Now, you should be able to use this script to call it.

import system system.util.execute(["C:\\DST.bat"])

EDIT: **At this point, you can do all sorts of dangerous things using batch files. Just be careful what you use. :wink:

Also, this command sets the clock to 1:00 AM. You probably already knew that, but I wanted to flesh this out.

Basically you’re replacing the original script with the one I provided, with the addition of the batch file.

Hope this helps!

EDIT: I don’t feel like I’m giving a good enough explanation.

One may ask "Why can’t I just use system.util.execute([“time 01:00”])? The reason is that system.util.execute() looks for a file to execute. TIME, in the DOS sense of the command, is built in to the command interpreter. There’s no separate TIME command.

The method I provided is rather a two-shot process. system.util.execute() runs the batch file, then the batch file runs TIME.

1 Like

Thanks Jordan. This server is actually islanded from the network so we can’t use windows auto update of DST.

The batch file was the solution that my co-worker had worked out, I just wanted to know if there was a way of getting javaos to work. I’d rather not have to worry about a batch file getting lost and would much rather have everything run through Ignition, but for now, it appears so far running on Windows Server takes os.system off the table.

Is this server part of a domain? If so the time will come from the “Domain Controller”. If it is not, and is stand alone for the ignition gateway you can just set the clock in the corner.

Our system requires that data be logged for every minute. The minute data is stored based on the Day Light Saving Time (unfortunately) so we need the time to change automatically at 2:00 am.

Its fuzzy I am not 100% here but my gut says…

I thought there was also the box to check to use “Daylight Savings” which I think would auto update the clock the hour each way in spring and fall.

There is, but the date changes every year so if the system is not connected to the internet, we are not guaranteed a correct change date.

it changes every year but the OS should already know which dates the time will change on.

The time and date will only be off what ever the internal system clock is off. I would check the clock at different intervals and see how much it is off. I think you will find it will be very, very close.

A server should/will be logged into often, at that time check the clock and set it if needed.

I hope we are helping.

Thank you all so far. We have already implemented a fix using batch files to change the time. I know the system time change ‘should’ work, but it was decided, not by me, that ignition would control the time change.

My real question was is it possible to get the os.system() function to work on Windows Server 2008 R2 since os.system() can usually be used to run anything that could be run in cmd.exe, such as changing the time or pinging etc.

[quote="MoreThanCarbon"]I know the system time change 'should' work, but it was decided, not by me, that ignition would control the time change.[/quote]You can tell them we think they're wrong. :wink:

The OS knows what the date should be, because the rules don't go by date. It goes by things like "The second Sunday in March to the first Sunday in November" (Which is what happens in the U.S. Eastern Time Zone). It's like Labor Day in the U.S. is the first Monday in September.

The point of all this is that the OS can and should handle the clock and DST. Not Ignition.

If they're worried about the DST rules changing, that's another story. But I have a solution for that, as well. Microsoft provides a free tool called TZEdit. You can either change the rules for an existing Time Zone, or make a new one. I provide the tool here, because links come and go, even at Microsoft. :slight_smile:tzedit.zip (23.1 KB)

My gut tells me no. I think It has to do with the jython version, but I don't remember when the switch was made to v2.5

This script will tell you what version of Jython you're running:

import sys print sys.version