@substrate-system/dupsh
v0.0.1
Published
Duplex stream for shell commands
Downloads
84
Readme
dupsh
pipe together two shell commands full duplex
Given two shell commands a and b, pipe the output of a to the input of b
and the output of b to the input of a:
a.stdout.pipe(b.stdin);
b.stdout.pipe(a.stdin);This is a TypeScript version of the classic dupsh module.
Install
npm i -S @substrate-system/dupshCLI
dupsh "CMD1" "CMD2"Use
usage: dupsh {OPTIONS} CMD1 CMD2
Spawn CMD1 and CMD2, piping the stdout of CMD1 to the stdin of CMD2,
and the stdout of CMD2 to the stdin of CMD1.
stderr from both processes is forwarded to the dupsh stderr.
OPTIONS are:
-h --help Show this message.Library API
import { dupsh, exec } from 'dupsh'type DupshCommand = string|readonly string[]
interface DupshOptions {
spawn?:SpawnOptionsWithoutStdio
stderr?:Writable
}
interface DupshResult {
left:ChildProcessWithoutNullStreams
right:ChildProcessWithoutNullStreams
completion:Promise<number>
}dupsh(leftCommand, rightCommand, options)starts both commands and returns process handles plus acompletionpromise.exec(leftCommand, rightCommand, options)is a convenience wrapper that resolves to the final exit code.- String commands run via shell (
shell: true) to preserve CLI-style command usage. - Array commands run directly without a shell (
[file, ...args]).
Programmatic example
import { exec } from 'dupsh'
const code = await exec(
[process.execPath, '-e', "process.stdout.write('A\\n')"],
[process.execPath, '-e', "process.stdout.write('B\\n')"]
)
process.exitCode = code