ApplesauceOS
Read Markdown ↗Download .md

execResult

Run a shell command and inspect its outcome.

js
execResult(command, asRoot = false, timeout = 0)

Arguments

ArgumentTypeMeaning
commandstringShell command; quote variable data correctly.
asRootbooleanfalse = mobile, true = root.
timeoutnumberSeconds, 0..86400; 0 means no deadline. Prefer a finite timeout.

Returns

{output, stdout, stderr, code, timedOut}; may also include error and outputTruncated.

Example

js
const r = execResult("id -u", false, 5);
if (r.error || r.timedOut || r.code !== 0) throw new Error(r.stderr || r.output);
console.log(r.stdout);

Notes

Output is limited to 256 KiB per stream. Cancellation requests cleanup of the command and its background descendants. A command can have side effects even when it times out.

All JavaScript APIs · Automation playbook