# 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.

```go
CmdLine = [ CmdOptions ] ["-"] [ CmdParameters ]
CmdParameters = { CmdParameter }
CmdParameter = ParamWithoutSpace | "Param With Spaces" | 'Param With Spaces'
CmdOptions = {CmdOption}
CmdOption = "-" | "--" {letter} [ CmdOptionValue | CmdOptionValues ]
CmdOptionValue = "=" | ":" CmdParameter
CmdOptionValues = " " CmdParameters
```

```
-p="my value" --flag - one two three
-i:10 -n:Bob "one par" two three
--ext "*.txt" .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2
```

* [Arg( str name ) str](/stdlib/process.md#arg-str-name-str)
* [Arg( str name, str def ) str](/stdlib/process.md#arg-str-name-str-def-str)
* [Arg( str name, int def ) int](/stdlib/process.md#arg-str-name-int-def-int)
* [ArgCount() int](/stdlib/process.md#argcount-int)
* [Args() arr.str](/stdlib/process.md#args-arr-str)
* [Args( str name ) arr.str](/stdlib/process.md#args-str-name-arr-str)
* [ArgsTail() arr.str](/stdlib/process.md#argstail-arr-str)
* [IsArg( str name ) bool](/stdlib/process.md#isarg-str-name-bool)
* [Open( str path )](/stdlib/process.md#open-str-path)
* [OpenWith( str app, str path )](/stdlib/process.md#openwith-str-app-str-path)
* [Run( str cmd, str params... )](/stdlib/process.md#run-str-cmd-str-params)
* [SplitCmdLine( str cmdline ) arr.str](/stdlib/process.md#splitcmdline-str-cmdline-arr-str)
* [Start( str cmd, str params... )](/stdlib/process.md#start-str-cmd-str-params)

## 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.

```
// --ext .txt .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2
list = Args(`--ext`) 
// list == [.txt, .js, .html]
```

### 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 **-**.

```
// --ext .txt .js .html -o=/home/ak/dest /home/ak/in1 /home/ak/in2
list = ArgsTail() // list == [/home/ak/in1, /home/ak/in2]

// -i=false - val0 -value1 "value 2" 
list = ArgsTail() // list == [val0, -value1, value 2]
```

### 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.

```go
    buf dirout
    Run("dir", stdout: dirout)
    Run("bash", stdin: buf(
      |`echo "dirs"
        #comment    
        echo "%{str(dirout)}"`
    ))
```

### SplitCmdLine(str cmdline) arr.str

The *SplitCmdLine* function parses the input string with command line parameters and returns an array of parameters.

```go
run str {
    return SplitCmdLine(`param1 "second par" "qwert\"y" 100 'oo ps'
-lastparam`).Join(`=`)
}
// returns param1=second par=qwert"y=100=oo ps=-lastparam
```

### 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.

```go
    Start("echo", "hello, world!")
    Start("bash", stdin: buf(
      |`./myscript1.sh
        ./myscript2.sh`
    ))
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gentee.org/stdlib/process.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
