UNPKG

1.56 kBJavaScriptView Raw
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//------------------------------------------------------------------------------
10// Requirements
11//------------------------------------------------------------------------------
12
13const crossSpawn = require("cross-spawn")
14
15//------------------------------------------------------------------------------
16// Helpers
17//------------------------------------------------------------------------------
18
19/**
20 * Kills the new process and its sub processes forcibly.
21 * @this ChildProcess
22 * @returns {void}
23 */
24function kill() {
25 crossSpawn("taskkill", ["/F", "/T", "/PID", this.pid])
26}
27
28//------------------------------------------------------------------------------
29// Public Interface
30//------------------------------------------------------------------------------
31
32/**
33 * Launches a new process with the given command.
34 * This is almost same as `child_process.spawn`.
35 *
36 * This returns a `ChildProcess` instance.
37 * `kill` method of the instance kills the new process and its sub processes forcibly.
38 *
39 * @param {string} command - The command to run.
40 * @param {string[]} args - List of string arguments.
41 * @param {object} options - Options.
42 * @returns {ChildProcess} A ChildProcess instance of new process.
43 * @private
44 */
45module.exports = function spawn(command, args, options) {
46 const child = crossSpawn(command, args, options)
47 child.kill = kill
48
49 return child
50}