System related slots for Hyperlambda

This project contains “system slots” to be able to invoke system commands. More specifically the project contains the following slots.

By combining the above slots with for instance the magic.lambda.sockets project, you can spawn off terminal/bash processes on your server, creating “virtual web based terminal sessions” on your server. To create a new terminal process, use something such as the following.

system.terminal.create:my-terminal
   folder:/

   /*
    * STDOUT callback, invoked when something is channeled over STDOUT.
    */
   .stdOut

      /*
       * Do standard out stuff here, with the incoming [.arguments]/[cmd] command.
       */
      log.info:x:@.arguments/*/cmd


   /*
    * STDERROR callback, invoked when something is channeled over STDOUT.
    */
   .stdErr

      /*
       * Do standard out stuff here, with the incoming [.arguments]/[cmd] command.
       */
      log.info:x:@.arguments/*/cmd

The above [.stdOut] and [.stdErr] lambda objects are invoked when output data or error data is received from the process, allowing you to handle it any ways you see fit. The [folder] argument is the default/initial folder to spawn of the process in. All of these arguments are optional.

The name or the value of the [system.terminal.create] invocation however is important. This becomes a unique reference for you, which you can later use to de-reference the instance, while for instance feeding the terminal lines of input, using for instance the [system.terminal.write-line] slot. To write a command line to an existing terminal window, such as the one created above, you can use something such as the following.

system.terminal.write-line:my-terminal
   cmd:ls -l

The above will execute the ls -l command in your previously create “my-terminal” instance, and invoke your [.stdOut] callback once for each line of output the command results in. To destroy the above created terminal, you can use something such as the following.

system.terminal.destroy:my-terminal

All terminal slots requires a name to be able to uniquely identify which instance you wish to create, write to, or destroy. This allows you to create as many terminals as you wish on your server, only restricted by memory on your system, and/or your operating system of choice. The terminal slots works transparently for both Windows, Linux and Mac OS X, except of course the commands you pass into them will differ depending upon your operating system.

Notice - If you don’t reference a terminal session for more than 30 minutes, the process will be automatically killed and disposed, and any future attempts to reference it, will resolve in an error. This is to avoid having hanging processes on the server, in case a terminal process is started, and then something happens, which disconnects the client, resulting in “hanging sessions”.

[system.execute]

If you only want to execute a specific program in your system you can use [system.execute], and pass in the name of the command as a value, and any arguments as children, optionally applying a [structured] argument to signifiy if you want each line of input to be returned as a single node or not. Below is an example.

system.execute:ls
   structured:true
   .:-l

The above will result in something such as follows.

system.execute
   .:total 64
   .:"-rw-r--r--  1 thomashansen  staff   495  9 Nov 10:37 Dockerfile"
   .:"-rw-r--r--  1 thomashansen  staff  1084 29 Oct 14:51 LICENSE"
   .:"-rw-r--r--  1 thomashansen  staff   604 29 Oct 14:51 Program.cs"
   .:"drwxr-xr-x  3 thomashansen  staff    96 29 Oct 16:53 Properties"
   .:"-rw-r--r--  1 thomashansen  staff  3154 29 Oct 14:51 Startup.cs"
   .:"-rw-r--r--  1 thomashansen  staff  1458 11 Nov 10:57 appsettings.json"
   .:"-rw-r--r--  1 thomashansen  staff   650  9 Nov 08:26 backend.csproj"
   .:"drwxr-xr-x  3 thomashansen  staff    96  9 Nov 10:23 bin"
   .:"-rw-r--r--  1 thomashansen  staff   700  9 Nov 07:29 dev_backend.csproj"
   .:"drwxr-xr-x  9 thomashansen  staff   288 12 Nov 10:31 files"
   .:"drwxr-xr-x  9 thomashansen  staff   288  9 Nov 19:05 obj"
   .:"drwxr-xr-x  6 thomashansen  staff   192 29 Oct 14:51 slots"
   .:"-rw-r--r--  1 thomashansen  staff  1905 29 Oct 14:51 web.config"

Notice - If you ommit the [structured] argument, or set its value to “false”, the result of the above invocation will return a single string.

Querying operating system version

In addition to the above slots this project also contains the following slots.

The last slot above takes an argument such as “Windows”, “OSX, “Linux”, etc, and will return true of the operating system you are currently running on belongs to the specified family of operating systems. Below is example usage of both.

system.is-os:OSX
system.os

Project website

The source code for this repository can be found at github.com/polterguy/magic.lambda.system, and you can provide feedback, provide bug reports, etc at the same place.

Quality gates