spawn-win32.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @module spawn-win32
  3. * @author Toru Nagashima
  4. * @copyright 2015 Toru Nagashima. All rights reserved.
  5. * See LICENSE file in root directory for full license.
  6. */
  7. 'use strict'
  8. // ------------------------------------------------------------------------------
  9. // Requirements
  10. // ------------------------------------------------------------------------------
  11. const crossSpawn = require('cross-spawn')
  12. // ------------------------------------------------------------------------------
  13. // Helpers
  14. // ------------------------------------------------------------------------------
  15. /**
  16. * Kills the new process and its sub processes forcibly.
  17. * @this ChildProcess
  18. * @returns {void}
  19. */
  20. function kill () {
  21. crossSpawn('taskkill', ['/F', '/T', '/PID', this.pid])
  22. }
  23. // ------------------------------------------------------------------------------
  24. // Public Interface
  25. // ------------------------------------------------------------------------------
  26. /**
  27. * Launches a new process with the given command.
  28. * This is almost same as `child_process.spawn`.
  29. *
  30. * This returns a `ChildProcess` instance.
  31. * `kill` method of the instance kills the new process and its sub processes forcibly.
  32. *
  33. * @param {string} command - The command to run.
  34. * @param {string[]} args - List of string arguments.
  35. * @param {object} options - Options.
  36. * @returns {ChildProcess} A ChildProcess instance of new process.
  37. * @private
  38. */
  39. module.exports = function spawn (command, args, options) {
  40. const child = crossSpawn(command, args, options)
  41. child.kill = kill
  42. return child
  43. }