Skip to content

Commit 48702a0

Browse files
author
Alexander Abroskin
committed
commands and scripts can catch stdin
1 parent 80ef72a commit 48702a0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/run.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
238238
return
239239
}
240240

241+
// pty part start
242+
defer func() { ptyOut.Close() }() // Make sure to close the pty at the end.
243+
// Copy stdin to the pty and the pty to stdout.
244+
go func() { io.Copy(ptyOut, os.Stdin) }()
241245
io.Copy(os.Stdout, ptyOut)
246+
// pty part end
242247

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

276281
command = exec.Command(runnerArg[0], runnerArg[1:]...)
277282
}
278-
command.Stdin = os.Stdin
279283

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

313+
// pty part start
314+
defer func() { ptyOut.Close() }() // Make sure to close the pty at the end.
315+
// Copy stdin to the pty and the pty to stdout.
316+
go func() { io.Copy(ptyOut, os.Stdin) }()
309317
io.Copy(os.Stdout, ptyOut)
318+
// pty part end
310319

311320
if command.Wait() == nil {
312321
okList = append(okList, executableName)

0 commit comments

Comments
 (0)