版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

99 строки
2.1 KiB

  1. "use strict";
  2. /**
  3. * An instance of this class is returned by {@link sync} and {@link async}.
  4. * It contains information about how the process was spawned, how it exited, and its output.
  5. */
  6. module.exports = class Process {
  7. /**
  8. * @param {object} props - Initial property values
  9. */
  10. constructor ({ command, args, pid, stdout, stderr, output, status, signal, options }) {
  11. options = options || {};
  12. stdout = stdout || (options.encoding === "buffer" ? Buffer.from([]) : "");
  13. stderr = stderr || (options.encoding === "buffer" ? Buffer.from([]) : "");
  14. output = output || [options.input || null, stdout, stderr];
  15. /**
  16. * The command that was used to spawn the process
  17. *
  18. * @type {string}
  19. */
  20. this.command = command || "";
  21. /**
  22. * The command-line arguments that were passed to the process.
  23. *
  24. * @type {string[]}
  25. */
  26. this.args = args || [];
  27. /**
  28. * The numeric process ID assigned by the operating system
  29. *
  30. * @type {number}
  31. */
  32. this.pid = pid || 0;
  33. /**
  34. * The process's standard output
  35. *
  36. * @type {Buffer|string}
  37. */
  38. this.stdout = output[1];
  39. /**
  40. * The process's error output
  41. *
  42. * @type {Buffer|string}
  43. */
  44. this.stderr = output[2];
  45. /**
  46. * The process's stdio [stdin, stdout, stderr]
  47. *
  48. * @type {Buffer[]|string[]}
  49. */
  50. this.output = output;
  51. /**
  52. * The process's status code
  53. *
  54. * @type {number}
  55. */
  56. this.status = status;
  57. /**
  58. * The signal used to kill the process, if applicable
  59. *
  60. * @type {string}
  61. */
  62. this.signal = signal || null;
  63. }
  64. /**
  65. * Returns the full command and arguments used to spawn the process
  66. *
  67. * @type {string}
  68. */
  69. toString () {
  70. let string = this.command;
  71. for (let arg of this.args) {
  72. // Escape quotes
  73. arg = arg.replace(/"/g, '\\"');
  74. if (arg.indexOf(" ") >= 0) {
  75. // Add quotes if the arg contains whitespace
  76. string += ` "${arg}"`;
  77. }
  78. else {
  79. string += ` ${arg}`;
  80. }
  81. }
  82. return string;
  83. }
  84. };