esc-get-interactive-cmd-result-async
v0.1.1
Published
async function that runs a shell command with arguments and environment variables, full interactive stdin/stdout/stderr usability (eg: run and use nano). Resolves/rejects with your command's return code.
Maintainers
Readme
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-asyncUsage
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 withprocess.env). - spawnO: Object – Extra
child_process.spawnoptions (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.
- env: Object (default:
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!
