Run shell script in child process, Output Observable<Buffer>


Keywords
npm run, run-script, rxjs, script, spawn
License
MIT
Install
npm install rxrunscript@5.1.3

Documentation

RxRunScript

Run shell script or command in Node.js child process, Output Observable<Buffer>

Version License Build Status Build status Coverage Status

Installing

$ npm install rxrunscript

Usage

import { OutputRow, run, take } from 'rxrunscript'

run('openssl version')
  .pipe(
    take(1),  // assume all output in one buffer
  )
  .subscribe({
    next: (row) => {
      console.log(row.data.toString()), 
    },
    error: (err) => {
      console.error(err),
    },
  }) 

// exec shell file
run('./test/openssl.sh')
  .subscribe({
    next: (row) => console.log(buf.toString()),
  })


import { reduce } from 'rxjs'

// win32
run('tasklist')
  .pipe(
    reduce((acc: Buffer[], curr: OutputRow) => {
      if (typeof curr.exitCode === 'undefined') {
        acc.push(curr)
      }
      return acc
    }, []),
  )
  .subscribe(
    arr => console.log(Buffer.concat(arr).toString()),
    err => console.error(err),
  )

// run cmd file
run('./test/prepare.cmd')
  .subscribe(
    row => console.log(row.data.toString()),
  )

License

MIT

Languages