📜  nodejs exec 退出代码 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:21.227000             🧑  作者: Mango

代码示例1
new Promise((resolve, reject) => {
  const child = exec('npm run something')

  if (child.stdout) {
    child.stdout.pipe(process.stdout)
  }

  if (child.stderr) {
    child.stderr.pipe(process.stderr)
  }

  child.on('exit', (code) => {
    if (code !== 0) {
      reject()
      return
    }

    resolve()
  })
})