MCPcopy
hub / github.com/nektos/act / exec

Method exec

pkg/container/host_environment.go:285–354  ·  view source on GitHub ↗
(ctx context.Context, command []string, cmdline string, env map[string]string, _, workdir string)

Source from the content-addressed store, hash-verified

283}
284
285func (e *HostEnvironment) exec(ctx context.Context, command []string, cmdline string, env map[string]string, _, workdir string) error {
286 envList := getEnvListFromMap(env)
287 var wd string
288 if workdir != "" {
289 if filepath.IsAbs(workdir) {
290 wd = workdir
291 } else {
292 wd = filepath.Join(e.Path, workdir)
293 }
294 } else {
295 wd = e.Path
296 }
297 f, err := lookupPathHost(command[0], env, e.StdOut)
298 if err != nil {
299 return err
300 }
301 cmd := exec.CommandContext(ctx, f)
302 cmd.Path = f
303 cmd.Args = command
304 cmd.Stdin = nil
305 cmd.Stdout = e.StdOut
306 cmd.Env = envList
307 cmd.Stderr = e.StdOut
308 cmd.Dir = wd
309 cmd.SysProcAttr = getSysProcAttr(cmdline, false)
310 var ppty *os.File
311 var tty *os.File
312 defer func() {
313 if ppty != nil {
314 ppty.Close()
315 }
316 if tty != nil {
317 tty.Close()
318 }
319 }()
320 if true /* allocate Terminal */ {
321 var err error
322 ppty, tty, err = setupPty(cmd, cmdline)
323 if err != nil {
324 common.Logger(ctx).Debugf("Failed to setup Pty %v\n", err.Error())
325 }
326 }
327 writer := &ptyWriter{Out: e.StdOut}
328 logctx, finishLog := context.WithCancel(context.Background())
329 if ppty != nil {
330 go copyPtyOutput(writer, ppty, finishLog)
331 } else {
332 finishLog()
333 }
334 if ppty != nil {
335 go writeKeepAlive(ppty)
336 }
337 err = cmd.Run()
338 if err != nil {
339 return err
340 }
341 if tty != nil {
342 writer.AutoStop = true

Callers 1

ExecWithCmdLineMethod · 0.95

Calls 10

LoggerFunction · 0.92
getEnvListFromMapFunction · 0.85
lookupPathHostFunction · 0.85
setupPtyFunction · 0.85
copyPtyOutputFunction · 0.85
writeKeepAliveFunction · 0.85
getSysProcAttrFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected