spawnAsync.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.spawnAsync = spawnAsync;
  6. var _child_process = require("child_process");
  7. /**
  8. * Copyright (c) Microsoft Corporation.
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. function spawnAsync(cmd, args, options = {}) {
  23. const process = (0, _child_process.spawn)(cmd, args, Object.assign({
  24. windowsHide: true
  25. }, options));
  26. return new Promise(resolve => {
  27. let stdout = '';
  28. let stderr = '';
  29. if (process.stdout) process.stdout.on('data', data => stdout += data.toString());
  30. if (process.stderr) process.stderr.on('data', data => stderr += data.toString());
  31. process.on('close', code => resolve({
  32. stdout,
  33. stderr,
  34. code
  35. }));
  36. process.on('error', error => resolve({
  37. stdout,
  38. stderr,
  39. code: 0,
  40. error
  41. }));
  42. });
  43. }