UNPKG

@zowe/imperative

Version:
47 lines 1.71 kB
"use strict"; /* * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html * * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. * */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ExecUtils = void 0; const spawn = require("cross-spawn"); /** * A collection of utilities related to executing a sub-process. * @export * @class ExecUtils */ class ExecUtils { /** * Spawn a process with arguments and throw an error if the process fails. * Parameters are same as `child_process.spawnSync` (see Node.js docs). * Use this method if you want the safe argument parsing of `spawnSync` * combined with the smart output handling of `execSync`. * @returns Contents of stdout as buffer or string */ static spawnAndGetOutput(command, args, options) { var _a; // Implementation based on the child_process module // https://github.com/nodejs/node/blob/main/lib/child_process.js const result = spawn.sync(command, args, options); if (result.error != null) { throw result.error; } else if (result.status !== 0) { let msg = `Command failed: ${command} ${args.join(" ")}`; if (((_a = result.stderr) === null || _a === void 0 ? void 0 : _a.length) > 0) { msg += `\n${result.stderr.toString()}`; } throw new Error(msg); } return result.stdout; } } exports.ExecUtils = ExecUtils; //# sourceMappingURL=ExecUtils.js.map