Wait should be called after Run(), and will return the outcome of the command execution.
()
| 271 | |
| 272 | // Wait should be called after Run(), and will return the outcome of the command execution. |
| 273 | func (gc *Command) Wait() (*Result, error) { |
| 274 | gc.mutex.Lock() |
| 275 | defer gc.mutex.Unlock() |
| 276 | |
| 277 | switch { |
| 278 | case gc.exec == nil: |
| 279 | return nil, ErrExecNotStarted |
| 280 | case gc.exec.err != nil: |
| 281 | return gc.result, gc.exec.err |
| 282 | case gc.result != nil: |
| 283 | return gc.result, ErrExecAlreadyFinished |
| 284 | } |
| 285 | |
| 286 | // Cancel the context in any case now |
| 287 | defer gc.exec.cancel() |
| 288 | |
| 289 | // Wait for the command |
| 290 | _ = gc.exec.command.Wait() |
| 291 | |
| 292 | // Capture timeout and cancellation |
| 293 | select { |
| 294 | case <-gc.exec.context.Done(): |
| 295 | default: |
| 296 | } |
| 297 | |
| 298 | // Wrap the results and return |
| 299 | err := gc.wrap() |
| 300 | |
| 301 | return gc.result, err |
| 302 | } |
| 303 | |
| 304 | // Signal sends a signal to the command. It should be called after Run() but before Wait(). |
| 305 | func (gc *Command) Signal(sig os.Signal) error { |