Skip to content

Commit

Permalink
Merge pull request atom#13320 from atom/jf-make-shell-invokation-deta…
Browse files Browse the repository at this point in the history
…ched

Run shell as detached process
  • Loading branch information
joefitzgerald authored and Antonio Scandurra committed Nov 25, 2016
1 parent 7c72c5c commit 5a3d615
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/update-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,32 @@ function shouldGetEnvFromShell (env) {

async function getEnvFromShell (env) {
let {stdout, error} = await new Promise((resolve) => {
let child
let error
let stdout = ''
const child = childProcess.spawn(env.SHELL, ['-ilc', 'command env'], {encoding: 'utf8', stdio: ['ignore', 'pipe', process.stderr]})
let done = false
const cleanup = () => {
if (!done && child) {
child.kill()
done = true
}
}
process.once('exit', cleanup)
setTimeout(() => {
cleanup()
}, 5000)
child = childProcess.spawn(env.SHELL, ['-ilc', 'command env'], {encoding: 'utf8', detached: true, stdio: ['ignore', 'pipe', process.stderr]})
const buffers = []
child.on('error', (e) => {
done = true
error = e
})
child.stdout.on('data', (data) => {
buffers.push(data)
})
child.on('close', (code, signal) => {
done = true
process.removeListener('exit', cleanup)
if (buffers.length) {
stdout = Buffer.concat(buffers).toString('utf8')
}
Expand Down

0 comments on commit 5a3d615

Please sign in to comment.