Prototype: execresult_as_data(command, shell, output)
Return type: data
The return value is cached.
Description: Execute command
and return a data container including command output and exit code.
Functions in the same way as execresult()
, and takes the same parameters. Unlike execresult()
, and returnszero()
, this function allows you to test, store, or inspect both exit code and output from the same command execution.
Arguments:
command
: string
- Fully qualified command path - in the range: .+
shell
: - Shell encapsulation option - one of
noshell
useshell
powershell
output
: - Which output to return; stdout or stderr - one of
both
stdout
stderr
Example:
Policy:
code
body common control
{
bundlesequence => { "example" };
}
bundle agent example
{
vars:
"my_data"
data => execresult_as_data("echo 'hello'", "useshell", "both");
"my_json_string"
string => storejson(my_data);
reports:
"echo 'hello' returned '$(my_json_string)'";
}
Output:
code
R: echo 'hello' returned '{
"exit_code": 0,
"output": "hello"
}'
Notes: you should never use this function to execute commands that make changes to the system, or perform lengthy computations. Consider using commands
promises instead, which have locking and are not evaluated by cf-promises
.
See also: execresult()
.
History:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4