Skip to main content

子进程使用

1、cmd#

方法#

cmd(file, arg, options)

使用#

异步调用

const res = cmd('lisa', ['-v'])res.stdout.pipe(process.stdout)await res

options#

可查阅api文档查看。下面列举几个常用的参数

类型描述
cwdstring执行的路径
envobject环境变量
encodingstring / null默认为utf8,若为null,则stdout为Buffer
timeoutnumber超时时间

2、exec#

方法#

exec(file, arg, options, onProcess)

使用#

同步调用

const code = await exec('lisa', ['-v'], {}, (line) => { console.log(line)})

返回#

返回该进程的exitCode

options#

与cmd的options一致

  • 没帮助 0