Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the run output log files to be populated when debug=true #53

Merged
merged 5 commits into from
Sep 28, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions venv.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func makeVenv(cfg VenvConfig) error {
}
logrus.Debugln("Detected Python version:", pythonVersion)

// venv was introduced in python version 3.3
// venv was introduced in python version 3.3
useVenv := pythonVersionAtLeast(pythonVersion, 3, 3)
logrus.Debugln("Use venv:", useVenv)

Expand Down Expand Up @@ -155,6 +155,22 @@ type VenvCommandRunOutput struct {
Exitcode int
}

func streamOutput(stream io.ReadCloser, outString *string) error {
var buff bytes.Buffer
reader := io.TeeReader(stream, &buff)

scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanLines)

for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
}
*outString = fmt.Sprint(buff.String())

return nil
}

// Run will execute the command described in VenvCommand.
//
// The strings returned are Stdout/Stderr.
Expand Down Expand Up @@ -203,16 +219,8 @@ func (c VenvCommand) Run() VenvCommandRunOutput {
return CommandOutput
}

for _, stream := range []io.ReadCloser{stdout, stderr} {
go func(s io.ReadCloser) {
scanner := bufio.NewScanner(s)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
}
}(stream)
}
go streamOutput(stdout, &CommandOutput.Stdout)
go streamOutput(stderr, &CommandOutput.Stderr)

if err := cmd.Wait(); err != nil {
exitError, _ := err.(*exec.ExitError)
Expand Down
Loading