我在使用 Node.js 里 spawn 来执行一段命令:
const codePushProcess = spawn('code-push', [
'release-react',
`rrs-${platform}`,
platform,
`--deploymentName=${deploymentName}`,
`--description=${desc}`,
`--targetBinaryVersion=${version}`,
'-m'
])
codePushProcess.stdout.on('data', chunk => {
console.log(chunk.toString('utf8'))
})
codePushProcess.stderr.on('data', data => {
console.error(`stderr: ${data}`)
})
codePushProcess.on('close', code => {
if (code === 0) {
console.log('CodePush Success!')
} else {
console.log(`CodePush process exited with code ${code}`)
}
})
遇到两个问题:
1
FaiChou OP |
2
FaiChou OP 解决了:
spawn('code-push', args, { stdio: 'inherit' }) 这个属性会将 stdio 传递给 parent process. https://nodejs.org/api/child_process.html#child_process_options_stdio 'inherit': Pass through the corresponding stdio stream to/from the parent process. In the first three positions, this is equivalent to process.stdin, process.stdout, and process.stderr, respectively. In any other position, equivalent to 'ignore'. |