Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/command-runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { exec } from "child_process";
import { exec, ChildProcess } from "child_process";
import OutputChannel from "./output-channel";
import { isCmdShell, getClickableLinksInMsg } from "./utils";
import {
Expand All @@ -19,8 +19,10 @@ interface IProcessHandlers {

class CommandRunner {
public isRunProcess: boolean = false;
private cp: ChildProcess | null = null;

public constructor(private outputChannel: OutputChannel) {}
public constructor(private outputChannel: OutputChannel) {
}

private resolveProcessSuccess(msg: string): StatusType {
this.outputChannel.showMessage(getClickableLinksInMsg(msg));
Expand All @@ -36,12 +38,20 @@ class CommandRunner {
cmdVal: string,
execOptions: Nullable<IExecOptions>
): Promise<StatusType> {
return new Promise((resolve) => {
exec(cmdVal, execOptions, (_, stdout, stderr) => {
const statusType: StatusType =
return new Promise((resolve, reject) => {
if (this.cp != null) {
let killed = this.cp.kill()
if (!killed) {
let statusType = this.resolveProcessError("previouse is not killed")
reject(statusType)
return
}
}
this.cp = exec(cmdVal, execOptions, (_, stdout, stderr) => {
let statusType: StatusType =
stderr !== ""
? this.resolveProcessError(String(stderr))
: this.resolveProcessSuccess(String(stdout));
? this.resolveProcessError(`stdout:${stdout}\nstderr${stderr}`)
: this.resolveProcessSuccess(`stdout:${stdout}\nstderr${stderr}`);

resolve(statusType);
});
Expand Down