Package detail

async-execute

omrilotan1.1kUNLICENSED2.0.0

🦅 Execute command in a child process

async, execute, exec, child_process

readme

async-execute

🦅 Execute command in a child process

import { execute } from "async-execute";

const commit_message = await execute("git log -1 --pretty=%B"); // Committed some changes

Options

Pipe stdout and stderr (default: false)

await execute("npm t", { pipe: true });

Exit process with child's exit code (default: false)

await execute("npm t", { pipe: true, exit: true });

Check a script exits properly

let code = 0;

try {
    const result = await execute("exit 2");
    code = result.code;
} catch (error) {
    code = error.code;
}

if (code > 0) {
    // something must have gone wrong
}

Any exec option can be passed

await execute("echo $API_KEY", {
    env: { API_KEY: "vQQNJe7lnz4rTbYvr61VywR0wRlRzCyI" },
});

await execute("pwd", { cwd: "~/app" });

changelog

CHANGELOG

2.0.0

  • Release as ESM named export
  • Pass through any options to child_process exec

1.2.0

  • Add exit code

1.1.0

  • Add optional pipe