0.0.2 • Published 7 years ago
rxjs-shell-operators v0.0.2
rxjs-shell-operators
rxjs operators for execute shell command with ease.
Features
- Wrap nodejs asynchronous process creation methods to rxjs Observable.
- Kill child process when unsubscribed.
- Use subject to communicate with child process.
Functions
exec(command, options) → Observable\<string>
optionsinterface is same with nodejsexecmethod
import {exec} from 'rxjs-shell-operators';
exec('echo Hello World')
.subscribe(output => {
console.log(output); // Hello World\n
});execFile(file, args) → Observable\<string>
optionsinterface is same with nodejsexecFilemethod
import {existSync} from 'fs';
import {execFile} from 'rxjs-shell-operators';
execFile('./touchFile.sh')
.subscribe(() => {
console.log(existSync('touched.txt')); // true
});spawn(command, args) → Observable\<Buffer>
spawnemitsstdout,stderr's buffer from command execution.optionsinterface is same with nodejsspawnmethod
import {spawn} from 'rxjs-shell-operators';
spawn('git clone http://github.com/johnny-mh/rxjs-shell-operators')
.pipe(tap(buf => process.stdout.write(String(buf))))
.subscribe();fork(modulePath, args) → Observable\<Buffer>
- same with
spawnbut have ownoptionsinterface that extend nodejs fork options to communicate with child process.
import {fork} from 'rxjs-shell-operators';
import {Subject} from 'rxjs';
const send = new Subject<string>();
const recv = new Subject<string>();
recv.subscribe(msgFromChildProc => console.log(msgFromChildProc));
fork('echo.js', undefined, {send, recv}).subscribe();
send.next('message to child process');