UNPKG

1.05 kBPlain TextView Raw
1#!/usr/bin/env node
2
3/**
4 * Script that will execute the downloaded phantomjs binary. stdio are
5 * forwarded to and from the child process.
6 *
7 * The following is for an ugly hack to avoid a problem where the installer
8 * finds the bin script npm creates during global installation.
9 *
10 * {NPM_INSTALL_MARKER}
11 */
12
13var path = require('path')
14var spawn = require('child_process').spawn
15
16var binPath = require(path.join(__dirname, '..', 'lib', 'phantomjs')).path
17
18var args = process.argv.slice(2)
19
20// For Node 0.6 compatibility, pipe the streams manually, instead of using
21// `{ stdio: 'inherit' }`.
22var cp = spawn(binPath, args)
23cp.stdout.pipe(process.stdout)
24cp.stderr.pipe(process.stderr)
25process.stdin.pipe(cp.stdin)
26
27cp.on('error', function (err) {
28 console.error('Error executing phantom at', binPath)
29 console.error(err.stack)
30})
31
32cp.on('exit', function(code){
33 // Wait few ms for error to be printed.
34 setTimeout(function(){
35 process.exit(code)
36 }, 20)
37});
38
39process.on('SIGTERM', function() {
40 cp.kill('SIGTERM')
41 process.exit(1)
42})