Skip to content

Commit

Permalink
Merge pull request #28 from line-o/doc/process-execute
Browse files Browse the repository at this point in the history
improve process:execute examples
  • Loading branch information
duncdrum authored Apr 8, 2019
2 parents 25074f6 + 54887ba commit dfb1522
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/main/xar-resources/data/docs/process/execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The eXistdb process module enables admin users to execute system command on the
* enviroment
* stdin

If you want to print environment variables or pass wildcard character to scripts it is necessary to call *sh*, *bash* or *zsh* with the -c option and provide the command as a single third parameter.


## Working Directory

Expand All @@ -19,10 +21,11 @@ return
process:execute(("ls","-l"),$options)
```
### Result

Lists the files in the directory '/etc' in long format (-l)


## Environment Variables
## Environment Variables

```xquery
let $options := \<option>
Expand All @@ -34,24 +37,46 @@ return
process:execute(("sh", "-c", "echo $DATA"), $options)
```


### Result

Echoes the value of the environment variable $DATA which is '/path/to/data'

## Wildcards / globbing

In order to pass wildcard characters down to the shell-script this must also be done using `sh -c`.

Note: **bash**, **zsh** and **sh** do have the `-c` option.

```xquery
let $options := \<option>
\<workingDir>/tmp\</workingDir>
\</option>
process:execute(("sh", "-c", "ls *.xml"), )
```

### Result

Lists all files with xml as their file extension.

**NOTE:** `process:execute(("ls", "*.xml"), $options)` returns an error.

## stdin
The command executed via process:execute reads the value(s) given as stdin argument(s)

```xquery
let $options := \<option>
\<stdin>
\<line>One</line>
\<line>Two</line>
\</stdin>
\</option>
\<stdin>
\<line>One</line>
\<line>Two</line>
\</stdin>
\</option>
return
process:execute(("wc", "-l"), $options)
```

### Result

The Unix command 'wc -l' prints the line count of the given argument (here <stdin>). The result is '2'.

0 comments on commit dfb1522

Please sign in to comment.