34 lines
889 B
TypeScript
34 lines
889 B
TypeScript
import { execFile } from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
|
|
const execFileAsync = promisify(execFile);
|
|
|
|
export async function execSchtasks(
|
|
args: string[],
|
|
): Promise<{ stdout: string; stderr: string; code: number }> {
|
|
try {
|
|
const { stdout, stderr } = await execFileAsync("schtasks", args, {
|
|
encoding: "utf8",
|
|
windowsHide: true,
|
|
});
|
|
return {
|
|
stdout: String(stdout ?? ""),
|
|
stderr: String(stderr ?? ""),
|
|
code: 0,
|
|
};
|
|
} catch (error) {
|
|
const e = error as {
|
|
stdout?: unknown;
|
|
stderr?: unknown;
|
|
code?: unknown;
|
|
message?: unknown;
|
|
};
|
|
return {
|
|
stdout: typeof e.stdout === "string" ? e.stdout : "",
|
|
stderr:
|
|
typeof e.stderr === "string" ? e.stderr : typeof e.message === "string" ? e.message : "",
|
|
code: typeof e.code === "number" ? e.code : 1,
|
|
};
|
|
}
|
|
}
|