|
Embedding CSL in batch files |
|
|
Typing csl in front of the script name becomes annoying sometimes. One solution to this may be to write a batch file / shell script which in turn will call csl. But CSL has also a feature to embed the script into the batch file itself. Windows and OS/2 If a file starts with '@', CSL will skip the first line and start compiling in the second line. Rename your file args.csl from our previous example to args.bat (Windows) or args.cmd (OS/2) and modify it this way:
@goto exec
#loadLibrary 'ZcSysLib'
main()
{
for (var i=0; i<sizeof(mainArgVals); i++)
sysLog(mainArgVals[i]);
}
/*
:exec
@csl %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
@rem */
You may now run the sample either with or without csl in front:
csl args my name is fred
...or...
args my name is fred
The output will however be the same in both cases: csl args my name is fred There is nothing magic about this. But what is actually going on? Since the extension of the file is .bat or .cmd respectively, the system runs it as a normal batch script by the command processor. The command processor in turn reads the first line and jumps down behind the :exec label where it calls the csl executive. The @rem line at the end hides the csl comment close from the command processor. For CSL this file looks as a perfect source too since it ignores the first line starting with '@'. Unixish systems If a file starts with '#!', CSL will skip the first line and start compiling in the second line. Rename your file args.csl from our previous example to args and modify it this way:
#!/usr/bin/env csl
#loadLibrary 'ZcSysLib'
main()
{
for (var i=0; i<sizeof(mainArgVals); i++)
sysLog(mainArgVals[i]);
}
Now you must tell the operating system, that args is an executable file: chmod 755 args You may now run the sample either with or without csl in front:
csl args my name is fred
...or...
args my name is fred
The output will however be the same in both cases (whereas the args line might also be ./args depending on the shell): csl args my name is fred |
||||||||
| Copyright © IBK Landquart | Last revision: 27.05.2002 | << Back Top Next >> |