silverbullet/plugos/syscalls/shell.deno.ts

25 lines
654 B
TypeScript
Raw Normal View History

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