Topic Options
#1342 - 12/23/00 08:38 AM Chapter A – Hello World!
Luke Tomasello Administrator Online   content
Member

Registered: 09/17/00
Posts: 739
Loc: San Jose, CA., USA
Welcome to the WinCron Tutorial.

In this first chapter of the Tutorial, we will present the quintessential ‘Hello World’ program.
Actually, WinCron doesn’t really have programs, but instead, jobs.

Jobs start with a ‘{‘ and end with a ‘}’, and have any number of statements in-between.

Okay, that’s the basics, now for the ‘Hello World’ job:

{
-action –print “Hello World!”
}

Now, there is a problem with the above job… It has no ‘start’ trigger.
You see, unlike programs written in 'C', C++, and perl, etc., WinCron scripts don’t have an entry point. WinCron scripts instead register triggers with the WinCron interpreter. These triggers tell WinCron when a job should fire.

Okay, lets now add a -start trigger.
In the following job, the start trigger has no arguments and therefore indicates that the job should fire now.

# This is a comment
{
# Start now!
-start

# Print Hello World!
-action -print “Hello World!”
}

Lets try our new script.
First save the script.
(I saved mine to c:\temp\hello.tg)

Launch WinCron:


Use the Load Button to load the script:


Use the Start button to start the WinCron interpreter:


Lets look at what we see on the WinCron console:
Ready.
Loading C:\Temp\hello.tg.
1 jobs loaded.
Trigger:unnamed: Saturday, December 23, 2000 13:09:25.
Hello World!


The first line output is what WinCron says when it enters a ready state.
WinCron will print Ready only once on startup, after all auto-run scripts have finished.

The next two lines simply indicate that WinCron has successfully loaded the script named ‘hello.tg’.
Additionally, the script that was loaded only contained 1 job. (It is possible that a single file loaded may contain multiple jobs.)

Finally you see the results of the script having been run.
The line:
Trigger:unnamed: Saturday, December 23, 2000 13:09:25.
Means, that on Saturday, December 23, 2000, at 13:09:25, an unnamed job was triggered.
The last line, Hello World!, is the output from the script.
_________________________
Regards,
Luke Tomasello

Top
#1343 - 08/28/01 02:25 PM Re: Chapter A – Hello World!
Luke Tomasello Administrator Online   content
Member

Registered: 09/17/00
Posts: 739
Loc: San Jose, CA., USA
Chapter A - Hello World, Part II

When we left off, our job looked like this:

# This is a comment
{
# Start now!
-start

# Print Hello World!
-action -print "Hello World!"
}

Jobs like the one above are called unnamed because they do not contain a -name directive.
It is not important to name your scripts unless:

1. You want your jobs to have meaningful names
2. You want to call jobs explicitly via the -call directive.

Otherwise, it is not important to name your scripts.
For examples sake, lets name our job 'my job'

# This is a comment
{
# Name our job
-name my job

# Start now!
-start

# Print Hello World!
-action -print "Hello World!"
}

Our script still doesn't do much, but to print 'Hello World!'

What makes a WinCron scripts useful, is the ability to reschedule the job to run recurrently.
The way this is accomplished is with the -inc directive.
-start -inc Days, Hours, Minutes and Seconds

# Reschedule job to run every day
{
# Name our job
-name my job

# Start now and Increment the day field.
# This will cause the job to fire NOW, and tomorrow at the same time
-start -inc 1 0 0 0

# Print Hello World!
-action -print "Hello World!"
}

In the above example, the -start directive assumes the current date/time.
After the job's trigger is evaluated, and if the job is in fact past due, then -inc directive is executed. This action increments the day field in the currently stored date, thus rescheduling the job for the following day.

For instance, if the start trigger is 12/23/2000 at 8:00:00 PM, then it would advance to 12/24/2000 at 8:00:00 PM after the -inc directive is executed.

Using the -inc directive, you can effectively reschedule jobs by seconds, minutes, hours or days.
_________________________
Regards,
Luke Tomasello

Top


Moderator:  Luke Tomasello