exec runs an ExecCommand and delivers the results to the program as a Msg.
(c ExecCommand, fn ExecCallback)
| 100 | |
| 101 | // exec runs an ExecCommand and delivers the results to the program as a Msg. |
| 102 | func (p *Program) exec(c ExecCommand, fn ExecCallback) { |
| 103 | if err := p.releaseTerminal(false); err != nil { |
| 104 | // If we can't release input, abort. |
| 105 | if fn != nil { |
| 106 | go p.Send(fn(err)) |
| 107 | } |
| 108 | return |
| 109 | } |
| 110 | |
| 111 | c.SetStdin(p.input) |
| 112 | c.SetStdout(p.output) |
| 113 | c.SetStderr(os.Stderr) |
| 114 | |
| 115 | // Execute system command. |
| 116 | if err := c.Run(); err != nil { |
| 117 | _ = p.RestoreTerminal() // also try to restore the terminal. |
| 118 | if fn != nil { |
| 119 | go p.Send(fn(err)) |
| 120 | } |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | // Have the program re-capture input. |
| 125 | err := p.RestoreTerminal() |
| 126 | if fn != nil { |
| 127 | go p.Send(fn(err)) |
| 128 | } |
| 129 | } |
no test coverage detected