Tutorial - Command Lines and Batch Files

Any programmer who lived through the early days of Unix shell scripts and DOS batch files will be familiar with all the concepts in this lesson. Feel free to skip to the next tutorial.

This is an option lesson aimed at people who grew up in the GUI world of Windows. It covers the use of batch files to speed up the development process.

For this example I am going to assume that you have installed the system in "C:\GraRLS_Free".

You could start creating you programs in one of the existing directories in the system; but it is recommended that you create a new directory - we will call it "MyWork" - within the installation directory giving "C:\GraRLS_Free\MyWork".

Next start by creating the core minimum program.

Program( )
    Begin

    End;

This should be given a name with the extension ".grs" - for now we will call it "myprog.grs" - and ensure it is in your working directory.

Now create a batch file in the same directory. This can be created with 'notepad' or any other text editor. The file should contain the following :-

..\grarls myprog.grs
pause

This should be saved in a file with the extension ".bat" ( we will call it "myprog.bat" ). To invoke the batch file you double click on it. If the 'pause' has been omitted then the command box will disappear before you can read the output. To get rid of the box just hit the 'enter' key.

The reason for the "..\" before grarls is because the actual program is in the directory above your working directory ( it is possible to add the appropriate directory to the system search path but it is not really worth it ).

This works because when you run a batch file by double clicking on it, it will run with the working directory set to the directory containing the batch file. This is not the case if you invoke the batch file with "Run as administrator" - which you will never need to do any way ( there is a way to deal with this, which I will leave you to look up yourself ).

Once you start filling out your program you may get error messages or other output. This can be redirected to a file by changing the batch file to :-

..\grarls myprog.grs > myprog.txt
pause

This will create ( or recreate ) the text file with any output. This can be read just by double clicking on it.

If you are working for a long time on a project it may be convenient to create a shortcut to put on the desktop. Right click on the batch file and select "Create shortcut". This will create :-

	myprog.bat - Shortcut

Now right click on the short cut and click on the "Properties" item. Ensure that the "Start in" field is the correct directory - edit it if it is not.

Once you have a working shortcut, you can drag it onto the desktop. You can also create a shortcut to your source file, output text file and image file.

Once the program is running normally it should produce a file named 'myprog.png' - assuming you are using the standard output file type.

It is worth reading up on the use of batch files - there are lots of tutorials on the Web. Also have a look at the batch files in the 'Examples' directory. These are a little more complex but it is worth finding out how they work.