Skip to main content
Home

@gnome/exec@0.6.0
Built and signed on GitHub Actions

Works with
This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score94%
Downloads7/wk
Publisheda year ago (0.6.0)

A cross-runtime module for invoking executables similar to child_process and Deno's Deno.Command.

Overview

The exec module provides cross-runtime functionality for invoke executables. A unified API is created for deno, node, bun to executables such as but not limited to git, which, echo, etc.

The API is influenced by Deno's Deno.Command api with some ehancements such as providing which and whichSync and converting string or objects into an array of arguments for the excutable.

Basic Usage

import { Command, command, run, output, type SplatObject, which } from "@gnome/exec";

// string, array, or objects can be used for "args".
const cmd1 = new Command("git", "show-ref master", {
    env: { "MY_VAR": "TEST" },
    cwd: "../parent"
});
const output = await cmd1.output();

console.log(output); // ->
// {
//    code: 0,
//    signal: undefined,
//    success: true
//    stdout: Uint8Array([01, 12..])
//    stderr: Uint8Array([0])
// }

// the output result has different methods on it..
console.log(output.text()) // text
console.log(output.lines()) // string[]
console.log(output.json()) // will throw if output is not valid json

const cmd1 = command("git", "show-ref master");

// these are the same.
console.log(await cmd1.output())
console.log(await cmd1);
console.log(await new Command("git", "show-ref master"));

console.log(await cmd1.text()); // get only the text from stdout instead

// pipe commands together
const result = await new Command("echo", ["my test"])
    .pipe("grep", ["test"])
    .pipe("cat")
    .output();

console.log(result.code);
console.log(result.stdout);

// output is the short hand for new Command().output()
// and output defaults stdout and stderr to 'piped'
// which returns the output as Uint8Array
const text = await output("git", ["show-ref", "master"]).then(o => o.text())
console.log(text);

MIT License

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@gnome/exec

Import symbol

import * as exec from "@gnome/exec";
or

Import directly with a jsr specifier

import * as exec from "jsr:@gnome/exec";

Add Package

pnpm i jsr:@gnome/exec
or (using pnpm 10.8 or older)
pnpm dlx jsr add @gnome/exec

Import symbol

import * as exec from "@gnome/exec";

Add Package

yarn add jsr:@gnome/exec
or (using Yarn 4.8 or older)
yarn dlx jsr add @gnome/exec

Import symbol

import * as exec from "@gnome/exec";

Add Package

vlt install jsr:@gnome/exec

Import symbol

import * as exec from "@gnome/exec";

Add Package

npx jsr add @gnome/exec

Import symbol

import * as exec from "@gnome/exec";

Add Package

bunx jsr add @gnome/exec

Import symbol

import * as exec from "@gnome/exec";