MCPcopy Create free account
hub / github.com/6174/comflowyspace / runCommand

Function runCommand

apps/node/src/modules/utils/run-command.ts:5–71  ·  view source on GitHub ↗
(
    command: string, 
    dispatcher: TaskEventDispatcher = () => { }, 
    options: Options = {}, 
    cb?: (process: ExecaChildProcess) => void
)

Source from the content-addressed store, hash-verified

3import { getSystemPath, getSystemProxy } from "./env";
4
5export async function runCommand(
6 command: string,
7 dispatcher: TaskEventDispatcher = () => { },
8 options: Options = {},
9 cb?: (process: ExecaChildProcess) => void
10): Promise<{
11 stderr: string,
12 exitCode: number,
13 stdout: string,
14}> {
15 const { systemProxy, systemProxyString } = await getSystemProxy();
16 if (systemProxy) {
17 logger.info("run command with proxy:" + command + " " + systemProxyString);
18 } else {
19 logger.info("run command without proxy")
20 }
21 const SHELL_ENV_PATH = getSystemPath({
22 CONDA_SCRIPTS_PATH: conda.info?.CONDA_SCRIPTS_PATH || "",
23 CONDA_ENV_PATH: conda.env?.CONDA_ENV_PATH || ""
24 });
25 const subProcess = execaCommand(command, {
26 env: {
27 ...process.env,
28 PATH: SHELL_ENV_PATH,
29 ...systemProxy,
30 },
31 // shell: isMac ? "/bin/zsh" : true,
32 ...options
33 });
34
35 cb && cb(subProcess);
36
37 subProcess.stdout?.on('data', (chunk) => {
38 logger.info("out", chunk.toString());
39 dispatcher && dispatcher({
40 message: chunk.toString()
41 })
42 });
43
44 subProcess.stderr?.on('data', (chunk) => {
45 logger.error(`run command "${command}" error: ${chunk.toString()}`);
46 dispatcher && dispatcher({
47 message: chunk.toString()
48 })
49 });
50
51 const { exitCode, stderr, stdout } = await subProcess;
52
53 dispatcher && dispatcher({
54 data: {
55 exitCode,
56 stderr,
57 stdout,
58 },
59 message: stderr + stdout
60 });
61
62 if (exitCode !== 0) {

Callers 14

checkComfyUIVersionFunction · 0.90
checkIfInstalledFunction · 0.90
installCondaTaskFunction · 0.90
installPythonTaskFunction · 0.90
installCondaPackageTaskFunction · 0.90
installPipPackageTaskFunction · 0.90
installPyTorchForGPUFunction · 0.90
cloneComfyUIFunction · 0.90
verifyIsTorchInstalledFunction · 0.90
installExtensionFunction · 0.90
gitCloneInstallFunction · 0.90
executeInstallScriptFunction · 0.90

Calls 4

getSystemProxyFunction · 0.90
getSystemPathFunction · 0.90
cbFunction · 0.85
onMethod · 0.45

Tested by

no test coverage detected