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.


  • command: string, in the range: .+
  • shell: one of
    • noshell
    • useshell
    • powershell
  • output: one of
    • both
    • stdout
    • stderr



body common control
      bundlesequence  => { "example" };

bundle agent example
        data => execresult_as_data("echo 'hello'", "useshell", "both");
        string => storejson(my_data);

      "echo 'hello' returned '$(my_json_string)'";



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().


  • Introduced in 3.17.0