Output and text files

Print

As can be seen in previous examples, the core of XSharper output is <print> action, which outputs a string to console.

To make output a bit nicer, mimic operating system streams, and also categorize output, there are 5 output options.

Name Purpose Default direction
^out Normal output Standard output
^bold More visible output, like section names etc. Standard output
^info Optional output Standard output, unless //quiet is specified
^error Error messages Standard error
^debug Debug messages None. Debug output (can be seen with dbgview utility) if //debug switch is specified. Also copied to standard output, if //debugc switch is specified
^nul,^null No output

In many actions it's possible to specify where the output goes via outTo attribute.

 

Also the same outTo may redirect the output to a variable

 

also if variable name is preceded by +, value is appended to the variable instead of overwriting it

 

Text file may be used for output using ^# prefix. Also, append is possible by using +^# prefix. Also, after | encoding may be specified (default to UTF8 with BOM)

 

By default, print appends a new line to every string output, that may be switched off using newline="false" attribute:

 

Redirection

Output to one stream may be redirected to another:
 

Or to a file (in UTF8 w/o BOM):
 

Or can add + to append:
 

ReadText

Reading a text file into a variable is easy.

 

Or just can out it to console instead:

 

If it's known in advance that the file is in UTF8

 

or

 

Or, if the file is on the web-server:

 

Finally, a multi-expression can be used as well (although XML often better demonstrates writer's intentions)

 

WriteText

Writing a text file is just as easy

 

To save as UTF16 with byte order mark:

 

Or, can just use print instead