smash-shell
A tiny shell command executor.
Install
执行 npm i --save smash-shell
或 yarn 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
-
Shell.execSync(command[, options])
-
command
: Legal command string. -
options
: Check thechild_process.execSync options
docs.
-
-
Shell.exec(command[, options])
- command: Legal command string.
- options: Check the
child_process.exec options
docs.