MCPcopy
hub / github.com/canopy-network/canopy / execCommand

Function execCommand

cmd/rpc/admin.go:841–864  ·  view source on GitHub ↗

execCommand executres the named program with the provided arguments, returning its output

(name string, arg ...string)

Source from the content-addressed store, hash-verified

839
840// execCommand executres the named program with the provided arguments, returning its output
841func execCommand(name string, arg ...string) ([]byte, error) {
842 // Create a new command to execute.
843 cmd := exec.Command(name, arg...)
844
845 // Initialize a buffer to capture the command output.
846 var buf bytes.Buffer
847
848 // Redirect both standard output and standard error to the buffer.
849 cmd.Stdout = &buf
850 cmd.Stderr = &buf
851
852 // Start the command execution.
853 if err := cmd.Start(); err != nil {
854 return buf.Bytes(), err
855 }
856
857 // Wait for the command to finish executing.
858 if err := cmd.Wait(); err != nil {
859 return buf.Bytes(), err
860 }
861
862 // Return the captured output and a nil error, indicating successful execution.
863 return buf.Bytes(), nil
864}

Callers 1

fdCountFunction · 0.85

Calls 2

BytesMethod · 0.65
StartMethod · 0.45

Tested by

no test coverage detected