app.js 943 B

123456789101112131415161718192021222324252627282930313233
  1. var spawn = require('child_process').spawn,
  2. self = require('../selenium-server'),
  3. fs = require('fs'),
  4. wd = __dirname + '/../..',
  5. args = process.argv.slice(2),
  6. selenium
  7. = spawn(
  8. 'java',
  9. ['-jar', self.path].concat(args)
  10. ),
  11. ok = false,
  12. out = fs.createWriteStream(wd + '/logs/selenium.out', {flags: 'a'}),
  13. err = fs.createWriteStream(wd + '/logs/selenium.err', {flags: 'a'});
  14. selenium.stderr.on('data', function(data) {
  15. if (/^execvp\(\)/.test(data)) {
  16. console.log('Failed to start selenium. Please ensure that java '+
  17. 'is in your system path');
  18. }
  19. else if (!ok) {
  20. ok = true;
  21. console.log("Selenium is started.");
  22. console.log("All output can be found at: " + wd + '/logs');
  23. }
  24. });
  25. selenium.stdout.pipe(out);
  26. selenium.stderr.pipe(err);
  27. process.on("SIGTERM", function () {
  28. selenium.kill("SIGTERM");
  29. process.exit(1);
  30. });