@ cush/ exec
简便 shell 执行
const exec = require('@cush/exec');
// Sync version
try {
const stdout = exec.sync('npm root -g');
console.log(stdout);
} catch(stderr) {
console.error(stderr);
}
// Async version
exec('git status --porcelain')
.then(stdout => {
console.log(stdout);
}, stderr => {
console.error(stderr);
});
// Child process options
const files = await exec('ls -a', {
cwd: 'path/to/dir'
});
// Additional arguments
const status = await exec('git status', [
porcelain ? '--porcelain' : null, // null and undefined values are filtered out
]);
描述可用的选项 这里。 。 。 .
页:1
- 当孩子过程的退出代码为非零时,就会出现出错(或拒绝承诺).