MCPcopy Index your code
hub / github.com/apache/devlake / RunProcess

Function RunProcess

backend/core/utils/ipc.go:112–158  ·  view source on GitHub ↗

RunProcess runs the cmd and blocks until its completion. All returned results will have type []byte.

(cmd *exec.Cmd, opts *RunProcessOptions)

Source from the content-addressed store, hash-verified

110
111// RunProcess runs the cmd and blocks until its completion. All returned results will have type []byte.
112func RunProcess(cmd *exec.Cmd, opts *RunProcessOptions) (*ProcessResponse, errors.Error) {
113 stream, err := StreamProcess(cmd, &StreamProcessOptions{
114 OnStdout: func(b []byte) {
115 if opts.OnStdout != nil {
116 opts.OnStdout(b)
117 }
118 },
119 OnStderr: func(b []byte) {
120 if opts.OnStderr != nil {
121 opts.OnStderr(b)
122 }
123 },
124 UseFdOut: opts.UseFdOut,
125 OnFdOut: func(b []byte) {
126 if opts.OnFdOut != nil {
127 opts.OnFdOut(b)
128 }
129 },
130 })
131 if err != nil {
132 return nil, err
133 }
134 var stdout []byte
135 var stderr []byte
136 var fdOut []byte
137 for result := range stream.Receive() {
138 if result.err != nil {
139 err = result.err
140 break
141 }
142 if result.stdout != nil {
143 stdout = append(stdout, result.stdout...)
144 }
145 if result.stderr != nil {
146 stderr = append(stderr, result.stderr...)
147 }
148 if result.fdOut != nil {
149 fdOut = append(fdOut, result.fdOut...)
150 }
151 }
152 return &ProcessResponse{
153 stdout: stdout,
154 stderr: stderr,
155 fdOut: fdOut,
156 err: err,
157 }, nil
158}
159
160// StreamProcess runs the cmd and returns its output on a line-by-line basis, on a channel. The converter functor will allow you
161// to convert the incoming raw to your custom data type T. This is a nonblocking function.

Callers

nothing calls this directly

Calls 2

StreamProcessFunction · 0.85
ReceiveMethod · 0.45

Tested by

no test coverage detected