| 131 | } |
| 132 | |
| 133 | func (this *Cmd) compose() *exec.Cmd { |
| 134 | if this.rawCmd != nil { |
| 135 | return this.rawCmd |
| 136 | } |
| 137 | |
| 138 | if this.ctx != nil { |
| 139 | this.rawCmd = exec.CommandContext(this.ctx, this.name, this.args...) |
| 140 | } else { |
| 141 | this.rawCmd = exec.Command(this.name, this.args...) |
| 142 | } |
| 143 | |
| 144 | if this.env != nil { |
| 145 | this.rawCmd.Env = this.env |
| 146 | } |
| 147 | |
| 148 | if len(this.dir) > 0 { |
| 149 | this.rawCmd.Dir = this.dir |
| 150 | } |
| 151 | |
| 152 | if this.captureStdout { |
| 153 | this.stdout = &bytes.Buffer{} |
| 154 | this.rawCmd.Stdout = this.stdout |
| 155 | } |
| 156 | if this.captureStderr { |
| 157 | this.stderr = &bytes.Buffer{} |
| 158 | this.rawCmd.Stderr = this.stderr |
| 159 | } |
| 160 | |
| 161 | return this.rawCmd |
| 162 | } |