MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / RunSimpleCommand

Function RunSimpleCommand

pkg/genconn/genconn.go:66–104  ·  view source on GitHub ↗
(ctx context.Context, client ShellClient, spec CommandSpec)

Source from the content-addressed store, hash-verified

64}
65
66func RunSimpleCommand(ctx context.Context, client ShellClient, spec CommandSpec) (string, string, error) {
67 proc, err := client.MakeProcessController(spec)
68 if err != nil {
69 return "", "", fmt.Errorf("failed to create process controller: %w", err)
70 }
71
72 stdout, err := proc.StdoutPipe()
73 if err != nil {
74 return "", "", fmt.Errorf("failed to get stdout pipe: %w", err)
75 }
76 stderr, err := proc.StderrPipe()
77 if err != nil {
78 return "", "", fmt.Errorf("failed to get stderr pipe: %w", err)
79 }
80
81 if err := proc.Start(); err != nil {
82 return "", "", fmt.Errorf("failed to start process: %w", err)
83 }
84
85 stdoutBuf := syncbuf.MakeSyncBuffer()
86 stderrBuf := syncbuf.MakeSyncBuffer()
87 var wg sync.WaitGroup
88 wg.Add(2)
89
90 go func() {
91 defer wg.Done()
92 io.Copy(stdoutBuf, stdout)
93 }()
94
95 go func() {
96 defer wg.Done()
97 io.Copy(stderrBuf, stderr)
98 }()
99
100 runErr := ProcessContextWait(ctx, proc)
101 wg.Wait()
102
103 return stdoutBuf.String(), stderrBuf.String(), runErr
104}
105
106func ProcessContextWait(ctx context.Context, proc ShellProcessController) error {
107 done := make(chan error, 1)

Callers 2

GetClientPlatformFunction · 0.92
GetClientPlatformFunction · 0.92

Calls 9

MakeSyncBufferFunction · 0.92
ProcessContextWaitFunction · 0.85
CopyMethod · 0.80
MakeProcessControllerMethod · 0.65
StdoutPipeMethod · 0.65
StderrPipeMethod · 0.65
StartMethod · 0.65
WaitMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected