esc-get-interactive-cmd-result-async
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

esc-get-interactive-cmd-result-async

Run any terminal command fully interactively from Node.js. Inherit stdio so the user can interact live—perfect for editors, shells, debuggers, installers, prompts, and more.

  • Pure, dependency-free
  • Promisified, simple API
  • All stdio is live—for full interactive experience
  • Output & input visible to user, as if run from your shell

My other NPM modules for capturing output from passive commands

Capture stdout or get custom arrays on error afterwards

esc-get-cmd-stdout-array-promise

Capture std out/err with optional advanced easy capture/filtering, error handling, live output passthru

esc-get-cmd-data-passthru-async


Install

npm install esc-get-interactive-cmd-result-async

Usage

Run a command such as nano, bash, less, or anything needing live terminal I/O:

import { runInteractivelyP } from 'esc-get-interactive-cmd-result-async';

try {
  // Open nano for the user as if in a regular terminal
  const exitCode = await runInteractivelyP('nano', ['/tmp/foo.txt'], {
    env: { DEBUG: '1' },
    verbosity: 2,           // (0-3), default: 3
    // spawnO: { cwd: '/tmp' } // set custom spawn options if needed
  });
  console.log('Nano closed with exit code', exitCode);
} catch (exitCode) {
  console.error('Editor closed with error/exit code', exitCode);
}

Any command will run truly interactively—input and output happen live in your terminal.


API

runInteractivelyP(cmd, argsA=[], optionsO={})

  • cmd: String – Command to run (e.g. 'bash', 'nano', 'vim')
  • argsA: Array<string> – Arguments for the command.
  • optionsO: Object
    • env: Object (default: {}) – Extra environment variables (merged with process.env).
    • spawnO: Object – Extra child_process.spawn options (e.g., {cwd})
    • verbosity: 0-3 (default: 3)
      • 0: silent, 1: errors, 2: show commands, 3: show success
    • rejectOnError: Boolean (default: true) – Rejects promise on exit code != 0. If false, always resolves.

Returns

A Promise which resolves (or rejects) with the exit code.

  • 0 = success, non-zero = error/failure/other exit

Features

  • No dependencies
  • 100% interactive I/O stdin/stdout/stderr all passed through
  • Promisified
  • Live terminal experience
  • Custom env, cwd, spawn control
  • Small: Under 2k of code
  • Stable API
  • Simple

Typical Use

  • Interactive editors (nano, vim)
  • Running login shells, REPLs, or live CLIs with user prompts
  • Running full-screen UIs (e.g., top, htop)
  • Install scripts, password prompts, utilities that require input

License

MIT


Star it: esc-get-interactive-cmd-result-async on GitHub
Issues & PRs welcome!


Package Sidebar

Install

npm i esc-get-interactive-cmd-result-async

Weekly Downloads

78

Version

0.1.1

License

MIT

Unpacked Size

7.66 kB

Total Files

5

Last publish

Collaborators

  • softwarecreations