diff --git a/libraries/deno-commons-mod.ts b/libraries/deno-commons-mod.ts index 47a1399..ea81067 100644 --- a/libraries/deno-commons-mod.ts +++ b/libraries/deno-commons-mod.ts @@ -3,6 +3,7 @@ import {decodeBase64, encodeBase64} from "jsr:@std/encoding/base64"; import {dirname, fromFileUrl} from "https://deno.land/std/path/mod.ts"; +import {spawn} from "node:child_process"; // reference: https://docs.deno.com/examples/hex_base64_encoding/ // import { decodeBase64, encodeBase64 } from "jsr:@std/encoding/base64"; @@ -100,13 +101,25 @@ export async function execCommandShell( args?: string[], options?: Deno.CommandOptions, ): Promise { - const opts = options || {}; - if (args) opts.args = args; - opts.stdin = "inherit"; - opts.stdout = "inherit"; - opts.stderr = "inherit"; - const cmd = new Deno.Command(command, opts); - return (await cmd.spawn().status).code; + if (isDeno()) { + const opts = options || {}; + if (args) opts.args = args; + opts.stdin = "inherit"; + opts.stdout = "inherit"; + opts.stderr = "inherit"; + const cmd = new Deno.Command(command, opts); + return (await cmd.spawn().status).code; + } else { + return new Promise((resolve, reject) => { + const ps = spawn(command, args, { + shell: false, + stdio: ["inherit", "inherit", "inherit"], + }); + ps.on('close', (code) => { + resolve(code); + }) + }); + } } export async function sleep(timeoutMillis: number): Promise {