You can invoke shell-commands during processing of a hsc source. The output of the command can be assigned to an special attribute or immediately being included into the document. This can be useful to include data from external applications (like databases), prepared by scripts (eg. Rexx), which of course you have to write yourself.
This functionality is provided by the hsc tag
stdout(or the filename specified with
FILE) is included in the document.
<$define>to store the data the command sends to
stdoutand will redirect the output to a temporary file. This attribute is only useful if you have also set at least one of
<$include>. Note that it can be reasonable to specify it, even if you set a specific output-file, and not only for temporary-files created by hsc.
REMOVE="off", the file will be left untouched. If no one else is going to remove it, it will continue to exist until doomsday or the next head-crash.
If you didn't specify an output filename (using
this can clutter your temporary-directory (usually "t:")
with loads of files having strange names like
To avoid this, you can set
REMOVE="on", so the output-file
will always be removed.
REMOVE="auto" is set. This will remove the
TEMPORARY has been enabled, and - if
INCLUDE has been activated, too - no messages
showed up during including the file.
<$exec>on important data without any backup, and always use
REMOVE="off"if your data are not really completely temporary.
Additionally, you can use all attributes of
<$include> that change
the appearance of the included data, like
SOURCE etc. - Of course, this only makes sense if the
INCLUDE-attribute has been set.
You can set both
one call to
<$exec COMMAND="list #?.hsc" TEMPORARY INCLUDE SOURCE PRE>
<$exec COMMAND="echo Hello! >echo.tmp" TEMPORARY INCLUDE FILE="echo.tmp">
<$exec COMMAND="list #?.hsc" ATTRIBUTE="output">
output; no data are included into the current document.
<$if COND=(HSC.SYSTEM="AMIGA")> <$exec COMMAND="list DIRS" TEMPORARY INCLUDE SOURCE PRE> <$elseif COND=(HSC.SYSTEM="UNIX")> <$exec COMMAND="ls -ld" TEMPORARY INCLUDE SOURCE PRE> <$else> <$message text="operating system not supported" class="warning"> </$if>And the data created by this code sequence would look like this:
drwxr-x--- 9 mb users 4096 Oct 14 16:57 .
As hsc is only a simple preprocessor, but not a programming language, it can not do certain things. For example, there are no string functions. But you can use external commands to gain the same result.
rx StripNastyChars.rexx bla:sülz:faselresults in
blaslzfaselIf you tried this yourself, you maybe noticed that the Rexx-script does not output a linefeed at the end of line. This is done by avoiding to use
SAY strippedto display the converted data. Instead, you will find a
call WriteCH(stdout, stripped)This simply is because StripNastyChars.hsc assigns the output of this script to a target attribute called
clean-databy means of
<$exec command=("rx StripNastyChars.rexx " + nasty-data) ATTRIBUTE=clean-data>Because of obvious reasons, the linefeed character created by
SAYwould be unwanted in the value of the target attribute. Therefor, the interesting part of the created HTML document will look like:
Converted "This#Text|Contains!Ñâ§ïÿ/Characters" to "ThisTextContainsCharacters".It should be easy for you to put this functionality in a macro.
Technically speaking, hsc redirects the output of you command by
appending a "
>filename" to the command-string.
For example, if you called
<$exec COMMAND="list #?.hsc" INCLUDE>
hsc will invoke the command like
list #?.hsc >hsc0x321764.tmp
with hsc0x321764.tmp chosen as temporary output file by
hsc. If you specify the
FILE attribute, you tell hsc
where to expect the output. But now you are responsible to redirect
it yourself. For example,
<$exec COMMAND="list #?.hsc >list.tmp" INCLUDE FILE="list.tmp"> <$exec COMMAND="list #?.hsc TO list.tmp" INCLUDE FILE="list.tmp">
will both create an output in list.tmp, where hsc will also look for it. But the next one will fail:
<$exec COMMAND="list #?.hsc >list.tmp" FILE="tmp.list">
The reason is obvious: The command outputs to list.tmp, but hsc tries to read tmp.list, which most likely will not exist.
Another problem will occur, if you redirect the output yourself
within the command call, but do not specify the
FILE-attribute: hsc will try to redirect the output twice:
<$exec COMMAND="list #?.hsc >list.tmp" INCLUDE>
will try to invoke something like
list #?.hsc >list.tmp >hsc0x321764.tmp
The behavior of this call is system dependent, but there's a general statement on this topic: it most likely won't work.