> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# sysExecute

> 执行系统命令或程序，并返回输出、错误和退出代码。

执行程序或命令。

## 必需的参数

* **name**: 执行的命令或程序的名称。

## 可选的参数

* **arguments**: 命令或程序的以空格分隔的命令行参数集（例如，`<arc:set attr="executable.arguments" value="arg1 arg2 arg3"/>`）。
* **argarray#**: 提供给命令或程序的参数数组。 该数组是通过为想要的每个索引（参数）创建一个“argarray#”条目来构建的（请参见下面的示例）。
* **directory**: 启动命令或程序的目录。默认值为 “.”。
* **timeout**: 等待命令或程序的最长时间（以秒为单位）。使用 -1 表示没有超时。默认值为 “60”。
* **waitforoutput**: 是否等待命令或程序的输出。默认值是 “true”。

## 输出属性

* **sys:output**: 命令或程序的输出。
* **sys:error**: 命令或程序的错误输出（如果有）。

## 示例

### .NET

```xml theme={null}
<!-- Creating an out item to hold output data -->
<arc:set attr="out.data" value=""/>
<!-- Creating an input item, 'executable' and assigning input parameters -->
<arc:set attr="executable.name" value="C:\\temp\\foo.bat" />
<!-- Creating an array of arguments that will be passed into the command or program -->
<arc:set attr="executable.argarray#1" value="arg1"/>
<arc:set attr="executable.argarray#2" value="arg2"/>
<arc:set attr="executable.argarray#3" value="arg3"/>
<!-- Calling the operation, passing in the input item and setting an output item -->
<arc:call op="sysExecute" in="executable" out="results">
  <!-- Populating the data attribute of the out item -->
  <arc:set attr="out.data" value="[results.sys:output]" />
</arc:call>
<!-- Setting the filename of the out item and pushing it as an output file -->
<arc:set attr="out.filename" value="echo.txt"/>
<arc:push item="out"/>
```

此处调用的批处理文件被编程为输出 `Hello world` 以及传入的参数列表。该脚本的输出（`echo.txt`）如下所示：

```
Hello world.
The first argument is arg1
The second argument is arg2
The third argument is arg3
```

### Linux

```xml theme={null}
<!-- Creating an out item to hold output data -->
<arc:set attr="out.data" value=""/>
<!-- Creating an input item, 'executable' and assigning input parameters -->
<arc:set attr="executable.name" value="bash" />
<arc:set attr="executable.arguments" value="/mnt/c/scripts/helloworld.sh lion tiger bear" />
<!-- Calling the operation, passing in the input item and setting an output item -->
<arc:call op="sysExecute" in="executable" out="results">
  <!-- Populating the data attribute of the out item -->
  <arc:set attr="out.data" value="[results.sys:output]" />
</arc:call>
<!-- Setting the filename of the out item and pushing it as an output file -->
<arc:set attr="out.filename" value="echo.txt"/>
<arc:push item="out"/>
```

此处调用的批处理文件被编程为输出 `hello linux world` 以及传入的参数列表。该脚本的输出（`echo.txt`）如下所示：

```
hello linux world
The first argument is lion
The second argument is tiger
The third argument is bear
```
