22 lines
473 B
TypeScript
22 lines
473 B
TypeScript
import { ExecOptions, execSync, ExecSyncOptions } from "child_process";
|
|
|
|
export default function execute(
|
|
cmd: string,
|
|
options?: ExecSyncOptions
|
|
): string | undefined {
|
|
try {
|
|
const res = execSync(cmd, {
|
|
encoding: "utf-8",
|
|
...options,
|
|
});
|
|
|
|
if (typeof res == "string") {
|
|
return res.trim();
|
|
} else {
|
|
return undefined;
|
|
}
|
|
} catch (error) {
|
|
return undefined;
|
|
}
|
|
}
|