Process
Operators and functions for working with processes and applications are described here. The Args and ArgCount functions work with any command line format. For the correct operation of other Arg... functions, the command line must have the following format.
1
CmdLine = [ CmdOptions ] ["-"] [ CmdParameters ]
2
CmdParameters = { CmdParameter }
3
CmdParameter = ParamWithoutSpace | "Param With Spaces" | 'Param With Spaces'
4
CmdOptions = {CmdOption}
5
CmdOption = "-" | "--" {letter} [ CmdOptionValue | CmdOptionValues ]
6
CmdOptionValue = "=" | ":" CmdParameter
7
CmdOptionValues = " " CmdParameters
Copied!
1
-p="my value" --flag - one two three
2
-i:10 -n:Bob "one par" two three
3
--ext "*.txt" .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2
Copied!

Operators

Operator
Result
Description
$ command line
Executes the command line.
str = $ command line
Executes the command line and returns its output.

Functions

Arg(str name) str

The Arg function returns the value of the parameter with the specified name. If the parameter was not specified at the start of the script, an empty string will be returned. You can omit the initial character - in the name parameter.

Arg(str name, str def) str

The Arg function returns the value of the parameter with the specified name. If the parameter was not specified at the start of the script, def will be returned. You can omit the initial character - in the name parameter.

Arg(str name, int def) int

The Arg function returns the numeric value of the parameter with the specified name. If the parameter was not specified at the start of the script, def will be returned. You can omit the initial character - in the name parameter.

ArgCount() int

The ArgCount function returns the number of command line parameters with which the script was run.

Args() arr.str

The Args function returns a list of all command-line parameters and options with which the script has been run.

Args(str name) arr.str

The Args function returns a list of parameter values named name. You can omit the initial character - in the name parameter.
1
// --ext .txt .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2
2
list = Args(`--ext`)
3
// list == [.txt, .js, .html]
Copied!

ArgsTail() arr.str

The ArgsTail function returns the list of command line parameters after the options. You can explicitly specify the beginning of such parameters with -.
1
// --ext .txt .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2
2
list = ArgsTail() // list == [/home/ak/in1, /home/ak/in2]
3
4
// -i=false - val0 -value1 "value 2"
5
list = ArgsTail() // list == [val0, -value1, value 2]
Copied!

IsArg(str name) bool

The IsArg function returns true if the command line has an option with the specified name. Otherwise, it returns false. You can omit the initial character - in the name parameter.

Open(str path)

The Open function opens a file, directory, or URI using the OS's default application for that object type. Don't wait for the open command to complete.

OpenWith(str app, str path)

The OpenWith function opens a file, directory, or URI using the specified application. Don't wait for the open command to complete.

Run(str cmd, str params...)

Optional parameters
    buf stdin - the buffer that will be passed to the application as standard input.
    buf stdout - the buffer into which the standard output of the application will be written.
    buf stderr - the buffer into which the standard error output of the application will be written.
The Run function starts the specified cmd program with parameters and waits for it to finish. Additionally, you can override the standard input and output.
1
buf dirout
2
Run("dir", stdout: dirout)
3
Run("bash", stdin: buf(
4
|`echo "dirs"
5
#comment
6
echo "%{str(dirout)}"`
7
))
Copied!

SplitCmdLine(str cmdline) arr.str

The SplitCmdLine function parses the input string with command line parameters and returns an array of parameters.
1
run str {
2
return SplitCmdLine(`param1 "second par" "qwert\"y" 100 'oo ps'
3
-lastparam`).Join(`=`)
4
}
5
// returns param1=second par=qwert"y=100=oo ps=-lastparam
Copied!

Start(str cmd, str params...)

Optional parameters
    buf stdin - the buffer that will be passed to the application as standard input.
The Start function starts the specified program cmd with parameters and runs the script further. Additionally, you can pass the buffer as standard input.
1
Start("echo", "hello, world!")
2
Start("bash", stdin: buf(
3
|`./myscript1.sh
4
./myscript2.sh`
5
))
Copied!
Last modified 1yr ago