diff --git a/examples/tests/sdk_tests/util/exec.test.w b/examples/tests/sdk_tests/util/exec.test.w index 83615488410..564328e3e52 100644 --- a/examples/tests/sdk_tests/util/exec.test.w +++ b/examples/tests/sdk_tests/util/exec.test.w @@ -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" diff --git a/libs/wingsdk/src/util/util.ts b/libs/wingsdk/src/util/util.ts index 61bc84c903f..633f8eeffc2 100644 --- a/libs/wingsdk/src/util/util.ts +++ b/libs/wingsdk/src/util/util.ts @@ -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"; @@ -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. @@ -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, opts?: ExecOptions - ): Promise { + ): Output { const execOpts = { windowsHide: true, shell: false, @@ -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) { @@ -252,7 +251,7 @@ export class Util { return { stdout: error.stdout.toString(), stderr: error.stderr.toString(), - status: error.code, + status: error.status, }; } }