Skip to content

Commit

Permalink
commands and scripts can catch stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Abroskin committed Nov 16, 2019
1 parent 80ef72a commit 48702a0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
return
}

// pty part start
defer func() { ptyOut.Close() }() // Make sure to close the pty at the end.
// Copy stdin to the pty and the pty to stdout.
go func() { io.Copy(ptyOut, os.Stdin) }()
io.Copy(os.Stdout, ptyOut)
// pty part end

if command.Wait() == nil {
okList = append(okList, commandName)
Expand Down Expand Up @@ -275,7 +280,6 @@ func executeScript(hooksGroup, source string, executable os.FileInfo, wg *sync.W

command = exec.Command(runnerArg[0], runnerArg[1:]...)
}
command.Stdin = os.Stdin

ptyOut, err := pty.Start(command)
mutex.Lock()
Expand Down Expand Up @@ -306,7 +310,12 @@ func executeScript(hooksGroup, source string, executable os.FileInfo, wg *sync.W
return
}

// pty part start
defer func() { ptyOut.Close() }() // Make sure to close the pty at the end.
// Copy stdin to the pty and the pty to stdout.
go func() { io.Copy(ptyOut, os.Stdin) }()
io.Copy(os.Stdout, ptyOut)
// pty part end

if command.Wait() == nil {
okList = append(okList, executableName)
Expand Down

0 comments on commit 48702a0

Please sign in to comment.