> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/components/system/execute.md).

# Execute

Component variation of Execute function

## Component Signature

```
<bx:Execute variable=[string]
name=[string]
arguments=[any]
timeout=[long]
terminateOnTimeout=[boolean]
directory=[string]
outputFile=[string]
errorFile=[string]
errorVariable=[string]
exitCode=[string]
inheritEnvironment=[boolean]
environment=[struct] />
```

### Attributes

| Atrribute            | Type      | Required | Description                                                                                     | Default |
| -------------------- | --------- | -------- | ----------------------------------------------------------------------------------------------- | ------- |
| `variable`           | `string`  | `false`  | The variable name to produce                                                                    |         |
| `name`               | `string`  | `true`   | The process name or binary path ( e.g. bash or /bin/sh )                                        |         |
| `arguments`          | `any`     | `false`  | The process arguments ( e.g. for `java --version` this would be `--version` )                   |         |
| `timeout`            | `long`    | `false`  | The timeout to wait for the command, in seconds ( default unlimited )                           |         |
| `terminateOnTimeout` | `boolean` | `false`  | Whether to terminate the process/command if a timeout is reached                                | `false` |
| `directory`          | `string`  | `false`  | A working directory to execute the command from                                                 |         |
| `outputFile`         | `string`  | `false`  |                                                                                                 |         |
| `errorFile`          | `string`  | `false`  | An optional file path to write errors to                                                        |         |
| `errorVariable`      | `string`  | `false`  | Optional variable to produce for error output                                                   |         |
| `exitCode`           | `string`  | `false`  | An optional variable to set the exit code into                                                  |         |
| `inheritEnvironment` | `boolean` | `false`  | Whether to inherit the parent process environment variables. Defaults to true.                  | `true`  |
| `environment`        | `struct`  | `false`  | A struct of environment variables to pass to the process. Merged in after the inherit decision. | `{}`    |

## Examples

### Script syntax

If you want to execute a script (.sh,.cmd,.bat), use bash (linux) or cmd.exe (windows) as the command and the script as argument for the shell interpreter.

```java
bx:execute name="bash" arguments="/opt/jq.sh #cmdArgs#" variable="standardOut" errorVariable="errorOut" timeout="10";

```

### Script syntax with terminateOnTimeout

Printing a PDF using lpr

```java
bx:execute name="lpr" arguments="-P 'My Print Job Name' 'C:/Users/devguy/Documents/server/mynewfile.pdf'" timeout="5" terminateOnTimeout="true";

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/components/system/execute.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
