MCPcopy Index your code
hub / github.com/coder/mux / execBuffered

Function execBuffered

src/node/utils/runtime/helpers.ts:37–68  ·  view source on GitHub ↗
(
  runtime: Runtime,
  command: string,
  options: ExecOptions & { stdin?: string }
)

Source from the content-addressed store, hash-verified

35 * Execute a command and buffer all output into strings
36 */
37export async function execBuffered(
38 runtime: Runtime,
39 command: string,
40 options: ExecOptions & { stdin?: string }
41): Promise<ExecResult> {
42 const stream = await runtime.exec(command, options);
43
44 // Write stdin if provided
45 if (options.stdin !== undefined) {
46 const writer = stream.stdin.getWriter();
47 try {
48 await writer.write(new TextEncoder().encode(options.stdin));
49 await writer.close();
50 } catch (err) {
51 writer.releaseLock();
52 throw err;
53 }
54 } else {
55 // Close stdin immediately if no input
56 await stream.stdin.close();
57 }
58
59 // Read stdout and stderr concurrently
60 const [stdout, stderr, exitCode, duration] = await Promise.all([
61 streamToString(stream.stdout),
62 streamToString(stream.stderr),
63 stream.exitCode,
64 stream.duration,
65 ]);
66
67 return { stdout, stderr, exitCode, duration };
68}
69
70/**
71 * Read file contents as a UTF-8 string

Callers 15

ensureGitInfoExcludeFunction · 0.90
generateMethod · 0.90
runWithHookFunction · 0.90
runPreHookFunction · 0.90
cleanupFunction · 0.90
runPostHookFunction · 0.90
tryReadGitHeadCommitShaFunction · 0.90
spawnProcessFunction · 0.90
getExitCodeMethod · 0.90

Calls 4

streamToStringFunction · 0.90
execMethod · 0.65
writeMethod · 0.65
closeMethod · 0.65

Tested by 2

execSSHFunction · 0.72
execWorkspaceFunction · 0.72