[comment]: # aside: 8

[comment]: # ({e7434dce-e8144915})
# JS

[comment]: # ({/e7434dce-e8144915})

[comment]: # ({4f9699bb-b0613168})
### 概述

`zabbix_js` 是一个命令行工具，可用于嵌入式脚本测试。

该工具会使用字符串参数执行用户脚本，并打印结果。
脚本通过嵌入式 Zabbix 脚本引擎执行。

如果发生编译或执行错误，`zabbix_js` 会将错误输出到 stderr，并以代码 `1` 退出。

[comment]: # ({/4f9699bb-b0613168})

[comment]: # ({9f28ffae-de3fe561})
### 用法

```default
zabbix_js -s script-file -p input-param [-l log-level] [-t timeout]
zabbix_js -s script-file -i input-file [-l log-level] [-t timeout]
zabbix_js -h
zabbix_js -V
```

`zabbix_js` 接受以下命令行参数：

```default
-s, --script script-file          指定要执行的脚本文件名
                                  如果将文件名指定为 "-"，则脚本将从 stdin 读取
-i, --input input-file            指定输入信息的文件名
                                  其内容将作为值传递给脚本
                                  与 -p 互斥
                                  如果将文件名指定为 "-"，则脚本将从 stdin 读取
-p, --param input-param           指定输入参数：要作为值传递给脚本的变量
                                  与 -i 互斥
-l, --loglevel log-level          指定日志级别
                                  范围：0-5
-t, --timeout timeout             指定超时时间（秒）
                                  有效范围：1-600 秒（默认值：10 秒）
-h, --help                        显示帮助信息
-V, --version                     显示版本号
-w <webdriver url>                启用浏览器监控
```

### 示例：

##### 示例 1：使用包含值的变量执行脚本

脚本（`script-file.js`）：

```default
return value;
```

用法：

```default
zabbix_js -s script-file.js -p example_value
```

输出：`example_value`

##### 示例 2：使用包含输入信息的文件执行脚本

脚本文件（`script-file.js`）：

```default
return value;
```

输入信息文件（`example.txt`）：

```default
Example of input information from the file
```

用法：

```default
zabbix_js -s script-file.js -i example.txt
```

输出：`Example of input information from the file`

##### 示例 3：使用从 stdin 读取的输入执行脚本

脚本文件（`script-file.js`）：

```default
return value;
```

用法：

```default
zabbix_js -s script-file.js -i -
```

输入（stdin）：

```default
Example of input from stdin
```

输出：`Example of input from stdin`

[comment]: # ({/9f28ffae-de3fe561})
