@viperhq/exec
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Simplified exec in NodeJs

npm

User input should be escaped!

Running bash

const bash = exec('/bin/bash', escapeBash);
const dirname = '/dev';

bash`
  ls -la ${dirname} > .tmp/dir.txt
  aws s3 cp .tmp/dir.txt s3://out/dir.txt
  rm .tmp/dir.txt
`

Getting things out of bash

const bash = exec();

const dir = bash.get`
  ls -la
`;

console.log(dir);

Standard input

const bash = exec();

const longString = 'longstring';

const processed = bash.get(longString)`
  cat | ./process
`;

console.log(processed);

Or

const bash = exec();

const longString = 'longstring';

bash.pipe(longString)`
  cat | ./process > .tmp/out.bin
  aws s3 cp .tmp/dir.txt s3://out/out.bin
  rm .tmp/out.bin
`;

Async

const bash = exec();

const longString = 'longstring';

const proc = bash.async`
  cat | ./process
`;

proc.stdin.end(longString);

let result = '';
process.stdout.on('data', chunk => (result += chunk));
process.stdout.end(() => console.log(result));

Readme

Keywords

Package Sidebar

Install

npm i @viperhq/exec

Weekly Downloads

0

Version

1.0.1

License

Apache-2.0

Unpacked Size

10.2 kB

Total Files

12

Last publish

Collaborators

  • artit91