|
5 | 5 | package impl
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "bufio" |
8 | 9 | "fmt"
|
9 | 10 | "io"
|
10 | 11 | "os"
|
@@ -726,8 +727,47 @@ func (d *Devbox) installNixProfile() (err error) {
|
726 | 727 | }
|
727 | 728 |
|
728 | 729 | cmd.Env = nix.DefaultEnv()
|
729 |
| - _, err = cmd.Output() |
| 730 | + |
| 731 | + // Get a pipe to read from standard out |
| 732 | + pipe, err := cmd.StdoutPipe() |
730 | 733 | if err != nil {
|
| 734 | + return errors.New("unable to open stdout pipe") |
| 735 | + } |
| 736 | + |
| 737 | + // Use the same writer for standard error |
| 738 | + cmd.Stderr = cmd.Stdout |
| 739 | + |
| 740 | + // Make a new channel which will be used to ensure we get all output |
| 741 | + done := make(chan struct{}) |
| 742 | + |
| 743 | + // Create a scanner which scans pipe in a line-by-line fashion |
| 744 | + scanner := bufio.NewScanner(pipe) |
| 745 | + |
| 746 | + // Use the scanner to scan the output line by line and log it |
| 747 | + // It's running in a goroutine so that it doesn't block |
| 748 | + go func() { |
| 749 | + |
| 750 | + // Read line by line and process it |
| 751 | + for scanner.Scan() { |
| 752 | + line := scanner.Text() |
| 753 | + step.Display(fmt.Sprintf("%s %s", msg, line)) |
| 754 | + } |
| 755 | + |
| 756 | + // We're all done, unblock the channel |
| 757 | + done <- struct{}{} |
| 758 | + }() |
| 759 | + |
| 760 | + // Start the command and check for errors |
| 761 | + if err := cmd.Start(); err != nil { |
| 762 | + step.Fail(msg) |
| 763 | + return errors.Errorf("error starting command %s: %v", cmd, err) |
| 764 | + } |
| 765 | + |
| 766 | + // Wait for all output to be processed |
| 767 | + <-done |
| 768 | + |
| 769 | + // Wait for the command to finish |
| 770 | + if err = cmd.Wait(); err != nil { |
731 | 771 | step.Fail(msg)
|
732 | 772 | return errors.Errorf("error running command %s: %v", cmd, err)
|
733 | 773 | }
|
|
0 commit comments