MCPcopy Index your code
hub / github.com/ddev/ddev / RunInteractiveCommandWithOutput

Function RunInteractiveCommandWithOutput

pkg/exec/exec.go:98–133  ·  view source on GitHub ↗

RunInteractiveCommandWithOutput writes to the host and also to the passed io.Writer

(command string, args []string, out io.Writer)

Source from the content-addressed store, hash-verified

96// RunInteractiveCommandWithOutput writes to the host and
97// also to the passed io.Writer
98func RunInteractiveCommandWithOutput(command string, args []string, out io.Writer) error {
99 cmd := HostCommand(command, args...)
100 cmd.Stdin = os.Stdin
101
102 pr, pw := io.Pipe()
103 defer func() {
104 _ = pr.Close()
105 }()
106 cmd.Stdout = pw
107 cmd.Stderr = pw
108
109 err := cmd.Start()
110 if err != nil {
111 return err
112 }
113
114 go func() {
115 _ = CleanAndCopy(out, pr)
116 _ = pr.Close()
117 }()
118
119 sigs := make(chan os.Signal, 1)
120 signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
121
122 // Goroutine to handle signals so the script can do the right thing
123 go func() {
124 sig := <-sigs
125 // Send the received signal to the child process
126 if err := cmd.Process.Signal(sig); err != nil {
127 panic(err)
128 }
129 }()
130
131 err = cmd.Wait()
132 return err
133}
134
135// RunHostCommand executes a command on the host and returns the
136// combined stdout/stderr results and error

Callers 2

debug-test.goFile · 0.92

Calls 4

HostCommandFunction · 0.85
CleanAndCopyFunction · 0.85
StartMethod · 0.80
WaitMethod · 0.80

Tested by

no test coverage detected