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

Method RunPipeToFile

agent/utils/cmd/cmdx.go:179–208  ·  view source on GitHub ↗
(outputFile string, commands ...PipeCommand)

Source from the content-addressed store, hash-verified

177}
178
179func (c *CommandHelper) RunPipeToFile(outputFile string, commands ...PipeCommand) (string, error) {
180 if len(commands) == 0 {
181 return "", nil
182 }
183
184 ctx, cancel, cmds := c.preparePipeCommands(commands)
185 if cancel != nil {
186 defer cancel()
187 }
188
189 file, err := os.OpenFile(outputFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, constant.FilePerm)
190 if err != nil {
191 return "", err
192 }
193 defer func() { _ = file.Close() }()
194
195 stderr := &lockedBuffer{limit: maxStreamOutputCapture}
196 if err := connectPipeCommands(cmds, file, stderr, stderr); err != nil {
197 return "", err
198 }
199 if err := startPipeCommands(cmds); err != nil {
200 return handleErrString("", stderr.String(), c.IgnoreExist1, err)
201 }
202
203 runErr := c.pipeResultErr(ctx, waitPipeCommands(ctx, cmds))
204 if runErr != nil {
205 return handleErrString("", stderr.String(), c.IgnoreExist1, runErr)
206 }
207 return "", nil
208}
209
210func (c *CommandHelper) preparePipeCommands(commands []PipeCommand) (context.Context, context.CancelFunc, []*exec.Cmd) {
211 ctx, cancel := c.pipeContext()

Callers 4

BackupMethod · 0.45
BackupMethod · 0.45
BackupMethod · 0.45
snapAppImageFunction · 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