phantomjs 1.0 KB

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