Capturing data from external sources

In addition to standard file I/O, Rax is capable of executing arbitrary system commands and capturing their output into a Rax variable. This functionality can be used for anything from running complex programs that generate large volumes of data to simply removing extraneous files generated by your Rax scripts. The syntax for executing a command and capturing its output is the same as for reading a file, but the command string should start with a pipe (|) character.

         $: fileNames := <$: "|ls">;     // Get a list of files in the current directory
         'print fileNames;               // Print them to standard output
       

The above example shows an extremely simple use of Rax's execution capabilities. Assuming that the Rax client is running on a Unix-based platform, Rax will successfully execute the ls command and capture the output generated by the program (i.e., a list of files in the current directory) and return them as a string variable. At the moment, Rax only supports capturing program output as a string, so structured data must be processed/filtered in subsequent steps.

Note that any command can be executed from within Rax, but special care must be taken when executing commands with complex arguments. In particular, arguments containing spaces or other special characters may require escaping, dependent upon the underlying operating system. As an example, creating a new file in a directory called "foo bar":

         $: ignore := <$: "|touch foo\ bar/baz">; // Create file in directory "foo bar"
         'print <$: "|ls foo\ bar">;              // Prints "baz"