exec command shell

This commit is contained in:
2026-02-11 01:10:19 +08:00
parent 2997939c8e
commit 7da86515df

View File

@@ -3,6 +3,7 @@
import {decodeBase64, encodeBase64} from "jsr:@std/encoding/base64"; import {decodeBase64, encodeBase64} from "jsr:@std/encoding/base64";
import {dirname, fromFileUrl} from "https://deno.land/std/path/mod.ts"; 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/ // reference: https://docs.deno.com/examples/hex_base64_encoding/
// import { decodeBase64, encodeBase64 } from "jsr:@std/encoding/base64"; // import { decodeBase64, encodeBase64 } from "jsr:@std/encoding/base64";
@@ -100,13 +101,25 @@ export async function execCommandShell(
args?: string[], args?: string[],
options?: Deno.CommandOptions, options?: Deno.CommandOptions,
): Promise<number> { ): Promise<number> {
const opts = options || {}; if (isDeno()) {
if (args) opts.args = args; const opts = options || {};
opts.stdin = "inherit"; if (args) opts.args = args;
opts.stdout = "inherit"; opts.stdin = "inherit";
opts.stderr = "inherit"; opts.stdout = "inherit";
const cmd = new Deno.Command(command, opts); opts.stderr = "inherit";
return (await cmd.spawn().status).code; 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<void> { export async function sleep(timeoutMillis: number): Promise<void> {