MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / runCommand

Function runCommand

apps/cli/src/service.ts:108–131  ·  view source on GitHub ↗
(
  cmd: string,
  args: ReadonlyArray<string>,
  env?: Record<string, string | undefined>,
)

Source from the content-addressed store, hash-verified

106}
107
108const runCommand = (
109 cmd: string,
110 args: ReadonlyArray<string>,
111 env?: Record<string, string | undefined>,
112): Effect.Effect<CommandResult, Error> =>
113 Effect.callback<CommandResult, Error>((resume) => {
114 const options = env
115 ? { encoding: "utf8" as const, env: { ...process.env, ...env } }
116 : { encoding: "utf8" as const };
117 execFile(cmd, [...args], options, (error, stdout, stderr) => {
118 // A string `code` (ENOENT etc.) means the command could not be spawned.
119 if (error && typeof (error as { code?: unknown }).code === "string") {
120 resume(
121 Effect.fail(new Error(`Failed to run \`${cmd}\`: ${(error as { code: string }).code}`)),
122 );
123 return;
124 }
125 const code =
126 error && typeof (error as { code?: unknown }).code === "number"
127 ? (error as { code: number }).code
128 : 0;
129 resume(Effect.succeed({ stdout: stdout ?? "", stderr: stderr ?? "", code }));
130 });
131 });
132
133const currentUid = (): number => {
134 const getuid = (process as { getuid?: () => number }).getuid;

Callers 4

makeLaunchdBackendFunction · 0.70
makeSystemdBackendFunction · 0.70
runSchtasksFunction · 0.70

Calls 1

resumeFunction · 0.85

Tested by

no test coverage detected