MCPcopy Index your code
hub / github.com/1Panel-dev/1Panel / RunPipeToFile

Method RunPipeToFile

core/utils/cmd/cmdx.go:158–187  ·  view source on GitHub ↗
(outputFile string, commands ...PipeCommand)

Source from the content-addressed store, hash-verified

156}
157
158func (c *CommandHelper) RunPipeToFile(outputFile string, commands ...PipeCommand) (string, error) {
159 if len(commands) == 0 {
160 return "", nil
161 }
162
163 ctx, cancel, cmds := c.preparePipeCommands(commands)
164 if cancel != nil {
165 defer cancel()
166 }
167
168 file, err := os.OpenFile(outputFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, constant.FilePerm)
169 if err != nil {
170 return "", err
171 }
172 defer func() { _ = file.Close() }()
173
174 stderr := &lockedBuffer{limit: maxStreamOutputCapture}
175 if err := connectPipeCommands(cmds, file, stderr, stderr); err != nil {
176 return "", err
177 }
178 if err := startPipeCommands(cmds); err != nil {
179 return handleErrString("", stderr.String(), c.IgnoreExist1, err)
180 }
181
182 runErr := c.pipeResultErr(ctx, waitPipeCommands(ctx, cmds))
183 if runErr != nil {
184 return handleErrString("", stderr.String(), c.IgnoreExist1, runErr)
185 }
186 return "", nil
187}
188
189func (c *CommandHelper) preparePipeCommands(commands []PipeCommand) (context.Context, context.CancelFunc, []*exec.Cmd) {
190 ctx, cancel := c.pipeContext()

Callers 1

runRemoteShellScriptFunction · 0.45

Calls 9

preparePipeCommandsMethod · 0.95
StringMethod · 0.95
pipeResultErrMethod · 0.95
OpenFileMethod · 0.80
connectPipeCommandsFunction · 0.70
startPipeCommandsFunction · 0.70
handleErrStringFunction · 0.70
waitPipeCommandsFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected