| 224 | } |
| 225 | |
| 226 | func (im *InceptionMain) Run() error { |
| 227 | var out bytes.Buffer |
| 228 | var errOut bytes.Buffer |
| 229 | |
| 230 | cmd := exec.Command(im.goCmd, "run", "-a", im.TempMainPath) |
| 231 | cmd.Stdout = &out |
| 232 | cmd.Stderr = &errOut |
| 233 | |
| 234 | err := cmd.Run() |
| 235 | |
| 236 | if err != nil { |
| 237 | return errors.New( |
| 238 | fmt.Sprintf("Go Run Failed for: %s\nSTDOUT:\n%s\nSTDERR:\n%s\n", |
| 239 | im.TempMainPath, |
| 240 | string(out.Bytes()), |
| 241 | string(errOut.Bytes()))) |
| 242 | } |
| 243 | |
| 244 | defer func() { |
| 245 | if im.tempExpose != nil { |
| 246 | im.tempExpose.Close() |
| 247 | } |
| 248 | |
| 249 | if im.tempMain != nil { |
| 250 | im.tempMain.Close() |
| 251 | } |
| 252 | |
| 253 | os.Remove(im.TempMainPath) |
| 254 | os.Remove(im.exposePath) |
| 255 | os.Remove(im.tempDir) |
| 256 | }() |
| 257 | |
| 258 | return nil |
| 259 | } |