Skip to content

Commit

Permalink
exec in preflight
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuf239 committed Aug 14, 2024
1 parent 46c65c1 commit d7168c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions examples/tests/sdk_tests/util/exec.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ let assertThrows = inflight (expected: str, block: (): void) => {
assert(error);
};

let output1 = util.exec("echo", ["-n", "Hello, Wing!"]);

expect.equal(output1.stdout, "Hello, Wing!");
expect.equal(output1.stderr, "");
expect.equal(output1.status, 0);


test "exec()" {
// "exec() with valid program"
Expand Down
13 changes: 6 additions & 7 deletions libs/wingsdk/src/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec, execFile } from "child_process";
import { exec, execFileSync } from "child_process";
import { createHash } from "crypto";
import { promisify } from "util";
import { nanoid, customAlphabet } from "nanoid";
Expand All @@ -9,7 +9,6 @@ import { InflightClient } from "../core";
import { Duration, IInflight } from "../std";

const execPromise = promisify(exec);
const execFilePromise = promisify(execFile);

/**
* Describes what to do with a standard I/O stream for a child process.
Expand Down Expand Up @@ -223,11 +222,11 @@ export class Util {
* @param opts `ExecOptions`, such as the working directory and environment variables.
* @returns A struct containing `stdout`, `stderr` and exit `status` of the executed program.
*/
public static async exec(
public static exec(
program: string,
args: Array<string>,
opts?: ExecOptions
): Promise<Output> {
): Output {
const execOpts = {
windowsHide: true,
shell: false,
Expand All @@ -239,10 +238,10 @@ export class Util {
};

try {
const { stdout, stderr } = await execFilePromise(program, args, execOpts);
const stdout = execFileSync(program, args, execOpts);
return {
stdout: stdout.toString(),
stderr: stderr.toString(),
stderr: "",
status: 0,
};
} catch (error: any) {
Expand All @@ -252,7 +251,7 @@ export class Util {
return {
stdout: error.stdout.toString(),
stderr: error.stderr.toString(),
status: error.code,
status: error.status,
};
}
}
Expand Down

0 comments on commit d7168c6

Please sign in to comment.