MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / start

Method start

common/src/process_tools.ts:36–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34 }
35
36 public start(): Promise<boolean> {
37 return new Promise((resolve, reject) => {
38 let timeTask: NodeJS.Timeout;
39 const subProcess = child_process.spawn(this.file, this.args, {
40 stdio: "pipe",
41 windowsHide: true,
42 cwd: path.normalize(this.cwd),
43 ...this.option
44 });
45 this.process = subProcess;
46 this.pid = subProcess.pid;
47
48 this.emit("start", subProcess.pid);
49 if (!subProcess || !subProcess.pid) return reject(new Error(this.errMsg.startErr));
50
51 subProcess.stdout.on("data", (text) => this.emit("data", iconv.decode(text, this.code)));
52 subProcess.stderr.on("data", (text) => this.emit("data", iconv.decode(text, this.code)));
53 subProcess.on("exit", (code) => {
54 try {
55 this.emit("exit", code);
56 this.destroy();
57 } catch (error: any) {}
58 if (timeTask) clearTimeout(timeTask);
59 if (code !== 0) return reject(new Error(this.errMsg.exitErr));
60 return resolve(true);
61 });
62
63 // timeout, terminate the task
64 if (this.timeout) {
65 timeTask = setTimeout(() => {
66 if (subProcess?.pid && !subProcess.exitCode && subProcess.exitCode !== 0) {
67 killProcess(subProcess.pid, subProcess);
68 reject(new Error(this.errMsg.timeoutErr));
69 } else {
70 reject(new Error(this.errMsg.exitErr));
71 }
72 }, 1000 * this.timeout);
73 }
74 });
75 }
76
77 public getPid() {
78 return this.process?.pid;

Callers 2

useUnzipFunction · 0.95
useZipFunction · 0.95

Calls 4

destroyMethod · 0.95
killProcessFunction · 0.85
emitMethod · 0.80
onMethod · 0.80

Tested by

no test coverage detected