How to make a script runnable

Advanced topics

1. Introduction
2. Under Windows (9x, NT, 2000, XP)
3. Under Unix


1. Introduction
If you're using aptilis for administrative jobs, you might be tired of typing:
\aptilis\aptilis.exe scriptName.e.txt
Wouldn't it be nice to just type something like:
scriptName ?
It can be done, but it's a slightly differently trick under Windows than it is under Unix.
We will use the following example (hello.e.txt) in both cases:

sub main(args[])

        print("That's my programm\n")
        print("Neat, eh?\n")

end main


2. Under Windows
In both cases we need to call the interpreter.
Here is how we do it under Windows:
First we need to change the code slightly:
@echo off
\aptilis\aptilis.exe hello.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
goto fin

sub main(args[])

        print("That's my programm\n")
        print("Neat, eh?\n")

end main

:fin
the 3 first lines disable batch output, call the interpreter and then cause the DOS interpreter to finish execution. What we do is to have an aptilis script being interpreted by the DOS command interpreter, but since this one does not understand aptilis, we have to hide the aptilis code from it, hence the 'goto'.
Then you have to rename your file, in this case 'hello.e.txt' to 'hello.bat'. Files whose extensions are '.bat' or '.cmd' are automatically passed to the command interpreter, and that's why you can now type 'hello' (without the quotes) at the command line and have your program run straightaway!
The "%1 %2 %3 %4 %5 %6 %7 %8 %9" is necessary to pass possible command line parameters to the script (they can be accessed via args[] - see the sub example 5)

This works because aptilis won't run anything outside a sub, so we can put what we want around them.
Unfortunately, unlike with Unix, this trick won't work for web scripts, although the people from Imatix who do the Xitami web server assure me that the Windows version of their product understands the #! trick as well as the Windows version of the Apache Web Server does.


3. Under Unix
First, the program needs to be modified:
#!/HostedWebSites/glaine/cgi-bin/aptilis.exe

sub main(args[])

        print("That's my programm\n")
        print("Neat, eh?\n")

end main
The first line instructs your shell what interpreter to use with that file. It's a bit simpler than under Windows, because Unix has been designed to do such things. You don't even need to change the name of your script!
Then, you need to tell Unix that this file can be run from the command line. You do that (for example in a telnet session) like this:
chmod 755 hello.e.txt

This works because aptilis won't run anything outside a sub, so we can put what we want around them.
The good thing about that is that the trick also works for web scripts, and you can call your script directly in the action parameter of your form tag, and no hidden file needs to be passed.