Skip to content

Commit

Permalink
wait for the comment to be Done
Browse files Browse the repository at this point in the history
fakoua committed Jan 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent dcbef9a commit 6124a1b
Showing 3 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ export type ShellResponse = {
stdout: string,
stderr: string,
exitCode: number,
state?: string,
error?: {
reason?: string,
message?: string
34 changes: 26 additions & 8 deletions src/winrm_context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as log from "https://deno.land/[email protected]/log/mod.ts";
import { parse } from "https://deno.land/x/[email protected]/mod.ts";
import { document, node } from "https://deno.land/x/[email protected]/utils/types.ts";
import { delay } from "https://deno.land/[email protected]/async/delay.ts";
import {
anyany,
BasicAuthentication,
@@ -116,11 +117,28 @@ export class WinRMContext {
};
}

const commandResponse = await this.getCommand(
messageId,
shellId,
commandId.message,
);
let cmd: ShellResponse;
const commandResponse: ShellResponse = {
exitCode: -100,
stderr: "",
stdout: "",
};
let counter = 0;
do {
console.log(counter++)
cmd = await this.getCommand(
messageId,
shellId,
commandId.message,
);
commandResponse.stdout = `${commandResponse.stdout}${cmd.stdout}`;

if (cmd.state?.endsWith("Running")) {
await delay(100);
} else {
commandResponse.exitCode = cmd.exitCode;
}
} while (cmd.state?.endsWith("Running"));

if (!this.isContextMode()) {
const deleteResponse = await this.deleteShellId(messageId, shellId);
@@ -137,7 +155,6 @@ export class WinRMContext {
return commandResponse;
}


/**
* Run powershell command
* @date 1/9/2024 - 2:53:51 PM
@@ -164,7 +181,6 @@ export class WinRMContext {
return this.runCommand(cmd);
}


/**
* Open a shell
* @date 1/9/2024 - 2:56:01 PM
@@ -205,7 +221,6 @@ export class WinRMContext {
return false;
}


/**
* Close a shell
* @date 1/9/2024 - 2:57:32 PM
@@ -318,9 +333,12 @@ export class WinRMContext {
}
}
}
const state =
(rResponseDocument["rsp:CommandState"] as document)["@State"];
return {
stderr: stderr.trim(),
stdout: stdout.trim(),
state: state?.toString(),
exitCode: exitCode,
};
} else {

0 comments on commit 6124a1b

Please sign in to comment.