MCPcopy
hub / github.com/lxc/incus / RunCommandSplit

Function RunCommandSplit

shared/subprocess/run.go:60–82  ·  view source on GitHub ↗

RunCommandSplit runs a command with a supplied environment and optional arguments and returns the resulting stdout and stderr output as separate variables. If the supplied environment is nil then the default environment is used. If the command fails to start or returns a non-zero exit code then an e

(ctx context.Context, env []string, filesInherit []*os.File, name string, arg ...string)

Source from the content-addressed store, hash-verified

58// the default environment is used. If the command fails to start or returns a non-zero exit code
59// then an error is returned containing the output of stderr too.
60func RunCommandSplit(ctx context.Context, env []string, filesInherit []*os.File, name string, arg ...string) (string, string, error) {
61 cmd := exec.CommandContext(ctx, name, arg...)
62
63 if env != nil {
64 cmd.Env = env
65 }
66
67 if filesInherit != nil {
68 cmd.ExtraFiles = filesInherit
69 }
70
71 var stdout bytes.Buffer
72 var stderr bytes.Buffer
73 cmd.Stdout = &stdout
74 cmd.Stderr = &stderr
75
76 err := cmd.Run()
77 if err != nil {
78 return stdout.String(), stderr.String(), NewRunError(name, arg, err, &stdout, &stderr)
79 }
80
81 return stdout.String(), stderr.String(), nil
82}
83
84// RunCommandContext runs a command with optional arguments and returns stdout. If the command fails to
85// start or returns a non-zero exit code then an error is returned containing the output of stderr.

Callers 12

runSkopeoMethod · 0.92
CallForkmknodFunction · 0.92
HandleSetxattrSyscallMethod · 0.92
HandleMountSyscallMethod · 0.92
DeviceEventHandlerMethod · 0.92
StartMethod · 0.92
RunACMEChallengeFunction · 0.92
RunCommandContextFunction · 0.85
RunCommandFunction · 0.85
RunCommandInheritFdsFunction · 0.85
RunCommandCLocaleFunction · 0.85

Calls 3

NewRunErrorFunction · 0.85
StringMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…