MCPcopy Index your code
hub / github.com/opencloud-eu/opencloud / RunRawCommand

Function RunRawCommand

tests/ocwrapper/opencloud/opencloud.go:275–306  ·  view source on GitHub ↗
(command string, inputs []string)

Source from the content-addressed store, hash-verified

273}
274
275func RunRawCommand(command string, inputs []string) (int, string) {
276 logs := new(strings.Builder)
277 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
278 defer cancel()
279
280 fmt.Print("Running command: ", command)
281
282 c := exec.CommandContext(ctx, "bash", "-c", command)
283
284 ptyF, err := pty.Start(c)
285 if err != nil {
286 log.Panic(err)
287 }
288 defer ptyF.Close()
289
290 for _, input := range inputs {
291 fmt.Fprintf(ptyF, "%s\n", input)
292 }
293
294 var cmdOutput string
295 if err := c.Wait(); err != nil {
296 if ctx.Err() == context.DeadlineExceeded {
297 cmdOutput = "Command timed out:\n"
298 }
299 }
300
301 io.Copy(logs, ptyF)
302 cmdOutput += logs.String()
303 cmdOutput = strings.TrimLeft(cmdOutput, strings.Join(inputs, "\r\n"))
304
305 return c.ProcessState.ExitCode(), cmdOutput
306}

Callers

nothing calls this directly

Calls 4

PrintMethod · 0.80
CloseMethod · 0.65
StartMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected