- Difficulty level: easy
- Time need to lean: 10 minutes or less
- Action
scriptis a general script execution action - Actions such as
Python2,Python3,Perlexecutes scripts with specified interpreters
- Action
Action script is the general form of all script-executing actions in SoS. It accepts a script, and parameters interpreter (required), suffix (if required by the interpreter) and optional args (command line arguments). It can be used to execute any script for which its interpreter is not currently supported by SoS. For example, the action
python:
print('HERE')
can be executed as
Action perl executes the passed script using perl interpreter.
Action ruby execute the passed script using ruby interpreter.
Action node executes the passed script using node (JavaScript) interpreter.
Action julia execute specified Julia script with command julia. Because my system does not have julia installed, the following example executes a Julia script in a docker container.
Action matlab execute specified matlab script with default options -nojvm -nodisplay -nosplash -r {filename:n};quit. The options start matlab without desktop, execute the strip (with parameter without .m extension), and quit matlab when the script is completed.
Action python and python3 accepts a Python script and execute it with python or python3, respectively.
Because SoS can include Python statements directly in a SoS script, it is important to note that embedded Python
statements are interpreted by SoS and the python and python3 actions are execute in separate processes without access to the SoS environment.
For example, the following SoS step execute some python statements within SoS with direct access to SoS variables such as input, and with result writing directly to the SoS environment,
[10]
for filename in input:
with open(filename) as data:
result = filename + '.res'
....
while
[10]
input: group_by='single'
python:
with open(${input!r}) as data:
result = ${input!r} + '.res'
...
composes a Python script for each input file and calls separate Python interpreters to execute them. Whereas
the Python statement in the first example will always be executed, the statements in python will not be executed in inspect mode.
In the following example, python actually calls Python 3 because version 3 is the default python interpreter on my system.
Action R(script) execute the passed script using Rscript command.
You can use parameter entrypoint to change the environment in which the interpreter will be executed. An entrypoint is usually the name of a shell script that defines a number of environment variables and run the command given by the command line parameters in such a way that the current process is replaced by it,
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
export MY_ENV=MY_VALUE
exec "$@"
but it can also be other commands such as micromamba run -n ENVIRONMENT.
For example, the following statement will execute interpreter Rscript
It's equivalent to the following statement