"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.execCmd = void 0;
const child_process_1 = require("child_process");
exports.execCmd = (cmd, args = null, options = null, stdout = 'debug', stderr = 'error', logger) => __awaiter(void 0, void 0, void 0, function* () {
    return new Promise((resolve, reject) => {
        let _stdout = '';
        const process = child_process_1.spawn(cmd, args, options);
        process.stdout.on('data', (data) => {
            logger.log('child_process')[stdout](data.toString());
            _stdout += data.toString();
        });
        process.stderr.on('data', (data) => logger.log('child_process')[stderr](data.toString()));
        process.on('close', (code) => {
            if (code === 0) {
                return resolve(_stdout);
            }
            return reject('Process exited with code ' + code);
        });
        process.on('error', (e) => {
            logger.log('child_process').error(e);
            return reject(e);
        });
    });
});
//# sourceMappingURL=child-process.js.map