compress-picture-js
Version:
42 lines (41 loc) • 1.84 kB
JavaScript
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());
});
};
import { execFile, execFileSync } from 'node:child_process';
// IsIExecCommandResult 是执行命令结果
export function IsIExecCommandResult(result) {
return result._isIExecCommandResult !== undefined;
}
// FromIExecCommandResult 是否是类型:IExecCommandResult
export function FromIExecCommandResult(result) {
return IsIExecCommandResult(result);
}
// ExecCommand 执行命令;不阻塞进程
export function ExecCommand(shell, commandArgs) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
execFile(shell, commandArgs, (error, stdout, stderr) => {
let result = {
_isIExecCommandResult: true,
error: error,
stdout: stdout,
stderr: stderr,
};
if (error) {
reject(result);
}
resolve(result);
});
});
});
}
// ExecCommandSync 执行命令
export function ExecCommandSync(shell, commandArgs) {
return execFileSync(shell, commandArgs, { encoding: 'utf-8' });
}