-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shell & command #154
Comments
macOS
/bin/sh是 POSIX-compliant shell interpreter, 是指定 shell 的 wrapper. |
node.js
|
execa interleaved output实际实现起来很简单 import {PassThrough} from 'stream'
import {exec} from 'child_process'
const bufferAll = new PassThrough({ encoding: 'utf8' })
let stdall = ''
bufferAll.on('data', (chunk) => {
stdall += chunk
})
try {
await new Promise((resolve, reject) => {
const child = exec(cmd, { shell: '/bin/zsh' }, (err, stdout, stderr) => {
if (err) return reject(err)
process.nextTick(() => resolve(undefined))
})
child.stdout.pipe(bufferAll)
child.stderr.pipe(bufferAll)
})
} catch (e) {
console.error('')
console.error('Error happens: ')
console.error('')
console.error(e.stack || e)
return
}
// 使用 stdall 即是混合了 stdout & stderr 的输出 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: