MCPcopy Index your code
hub / github.com/coder/coder / runLocal

Function runLocal

cli/ssh.go:1206–1228  ·  view source on GitHub ↗

runLocal runs a command on the local machine.

(ctx context.Context, stdin io.Reader, name string, args ...string)

Source from the content-addressed store, hash-verified

1204
1205// runLocal runs a command on the local machine.
1206func runLocal(ctx context.Context, stdin io.Reader, name string, args ...string) ([]byte, error) {
1207 cmd := exec.CommandContext(ctx, name, args...)
1208 cmd.Stdin = stdin
1209
1210 out, err := cmd.Output()
1211 if err != nil {
1212 var stderr []byte
1213 if exitErr := new(exec.ExitError); errors.As(err, &exitErr) {
1214 stderr = exitErr.Stderr
1215 }
1216
1217 return out, xerrors.Errorf(
1218 "`%s %s` failed: stderr: %s\n\nstdout: %s\n\n%w",
1219 name,
1220 strings.Join(args, " "),
1221 bytes.TrimSpace(stderr),
1222 bytes.TrimSpace(out),
1223 err,
1224 )
1225 }
1226
1227 return out, nil
1228}
1229
1230// runRemoteSSH runs a command on a remote machine/workspace via SSH.
1231func runRemoteSSH(sshClient *gossh.Client, stdin io.Reader, cmd string) ([]byte, error) {

Callers 2

uploadGPGKeysFunction · 0.85
localGPGExtraSocketFunction · 0.85

Calls 4

AsMethod · 0.80
CommandContextMethod · 0.65
OutputMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected