0.0.1 • Published 5 years ago

smash-shell v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

smash-shell

A tiny shell command executor.

Install

执行 npm i --save smash-shellyarn add smash-shell 安装。

Usage

const Shell = require('smash-shell');
const cwd = path.normalize(path.resolve(__dirname, '.'));
const command = 'git log';
const options = {
    cwd,
    encoding: 'utf8',
    maxBuffer: 200 * 1024, // 200kb
};

// Shell.execSync
const { error, stdout } = Shell.execSync(command, options);
if (error) {
    console.log(error.message);
} else {
    console.log(stdout);
}

// Shell.exec
Shell.exec(command, options).then(({ error, stdout, stderr }) => {
    if (error) {
        console.log(error.message);
    } else {
        console.log(stdout);
    }
});

API

  1. Shell.execSync(command[, options])

  2. Shell.exec(command[, options])

Links