exec command shell
This commit is contained in:
@@ -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,6 +101,7 @@ export async function execCommandShell(
|
|||||||
args?: string[],
|
args?: string[],
|
||||||
options?: Deno.CommandOptions,
|
options?: Deno.CommandOptions,
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
|
if (isDeno()) {
|
||||||
const opts = options || {};
|
const opts = options || {};
|
||||||
if (args) opts.args = args;
|
if (args) opts.args = args;
|
||||||
opts.stdin = "inherit";
|
opts.stdin = "inherit";
|
||||||
@@ -107,6 +109,17 @@ export async function execCommandShell(
|
|||||||
opts.stderr = "inherit";
|
opts.stderr = "inherit";
|
||||||
const cmd = new Deno.Command(command, opts);
|
const cmd = new Deno.Command(command, opts);
|
||||||
return (await cmd.spawn().status).code;
|
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> {
|
||||||
|
|||||||
Reference in New Issue
Block a user