1
0
silverbullet/plugos/syscalls/shell.deno.ts

24 lines
603 B
TypeScript
Raw Normal View History

import type { SysCallMapping } from "../system.ts";
2023-08-04 16:56:55 +00:00
export function shellSyscalls(cwd: string): SysCallMapping {
return {
"shell.run": async (
_ctx,
cmd: string,
args: string[],
): Promise<{ stdout: string; stderr: string }> => {
2023-08-04 16:56:55 +00:00
const p = new Deno.Command(cmd, {
args: args,
cwd,
stdout: "piped",
stderr: "piped",
});
2023-08-04 16:56:55 +00:00
const output = await p.output();
const stdout = new TextDecoder().decode(output.stdout);
const stderr = new TextDecoder().decode(output.stderr);
return { stdout, stderr };
},
};
}