Skip to content

Commit

Permalink
When debug is true the output to log files fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashritha Goramane committed Sep 11, 2024
1 parent e669188 commit 1a7a8f2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions venv.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,27 @@ func (c VenvCommand) Run() VenvCommandRunOutput {
CommandOutput.Error = errors.Wrap(err, "unable to start command")
return CommandOutput
}

output := map[io.ReadCloser]*string{
stdout: &CommandOutput.Stdout,
stderr: &CommandOutput.Stderr,
}

for _, stream := range []io.ReadCloser{stdout, stderr} {
go func(s io.ReadCloser) {
for stream, out := range output {
go func(s io.ReadCloser, o *string) {
var bufstdout bytes.Buffer

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

for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
bufstdout.WriteString(m)
bufstdout.WriteString("\n")
}
}(stream)
*o = fmt.Sprint(bufstdout.String())
}(stream, out)
}

if err := cmd.Wait(); err != nil {
Expand Down

0 comments on commit 1a7a8f2

Please sign in to comment.