Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created November 29, 2016 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/36512d696f11288fc106e67644f0b8f5 to your computer and use it in GitHub Desktop.
Save isaacs/36512d696f11288fc106e67644f0b8f5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
if (process.env.xyz) {
console.log('in t.js, xyz=%j', process.env.xyz)
console.log('gc is a', typeof gc)
console.log('%s %j', process.execPath, process.execArgv.concat(process.argv))
console.log('node@%s', process.version)
console.log('about to run the main file\u001b[32m')
require('./index.js').runMain()
console.log('\u001b[31mran wrapped main')
return
}
var wrap = require('./index.js')
var unwrap = wrap(['--expose_gc', __filename, ' a $ b '], { xyz: 'ABC' })
console.log('about to run child process')
console.log('gc is a', typeof gc)
var cp = require('child_process')
var node = process.env.NODE || process.execPath
console.error('node=%s', node)
var child = cp.exec(node+ ' $(which tap ) -v', { env: { foo: 'asdf', PATH:process.env.PATH } }, function (er, out, err) {
console.error('returned')
console.error('error = ', er)
console.error('outlen=', out.length)
console.error('\u001b[31m' + out + '\u001b[m')
console.error('errlen=', err.length)
process.stderr.write(err)
})
@isaacs
Copy link
Author

isaacs commented Nov 29, 2016

Running this in a NAVE shell, where process.execPath will be something other than the supplied NODE environ:

$ NODE=/usr/local/bin/node node t.js
about to run child process
gc is a undefined
node=/usr/local/bin/node
WRAPPED /bin/sh [ '/bin/sh',
  '-c',
  ' /Users/isaacs/.node-spawn-wrap-79628-235f4ce0c1b4/node $(which tap ) -v' ]
returned
error =  null
outlen= 291
in t.js, xyz="ABC"
gc is a function
/Users/isaacs/.nave/installed/6.9.1/bin/node ["--expose_gc","/Users/isaacs/.nave/installed/6.9.1/bin/node","/Users/isaacs/dev/js/spawn-wrap/t.js"," a $ b ","/usr/local/bin/tap","-v"]
node@v6.9.1
about to run the main file
8.0.1
ran wrapped main

errlen= 0

@isaacs
Copy link
Author

isaacs commented Nov 29, 2016

Note that it's running /Users/isaacs/.nave/installed/6.9.1/bin/node, not /usr/local/bin/node, which was the one that was being replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment