From 000e763a61cd36a896d5eea8adc2079fa90207e5 Mon Sep 17 00:00:00 2001 From: nikitar020 <42252263+nikitar020@users.noreply.github.com> Date: Mon, 18 Mar 2019 17:49:37 +0200 Subject: [PATCH] Make shells running on Windows (#260) --- platform/winpty.go | 43 ++----------------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/platform/winpty.go b/platform/winpty.go index 4bc1dc2..386ec79 100644 --- a/platform/winpty.go +++ b/platform/winpty.go @@ -4,12 +4,8 @@ package platform import ( "errors" - "syscall" - "time" - - "fmt" - "github.com/MaxRis/w32" + "syscall" ) // #include "windows.h" @@ -144,42 +140,7 @@ func (pty *winConPty) CreateGuestProcess(imagePath string) (Process, error) { pty.processID = process.processID - err = setupChildConsole(C.DWORD(process.processID), C.STD_OUTPUT_HANDLE, C.ENABLE_PROCESSED_OUTPUT|C.ENABLE_WRAP_AT_EOL_OUTPUT) - if err != nil { - process.Close() - return nil, err - } - - return process, err -} - -func setupChildConsole(processID C.DWORD, nStdHandle C.DWORD, mode uint) error { - C.FreeConsole() - defer C.AttachConsole(^C.DWORD(0)) // attach to parent process console - - // process may not be ready so we'll do retries - const maxWaitMilliSeconds = 5000 - const waitStepMilliSeconds = 200 - count := maxWaitMilliSeconds / waitStepMilliSeconds - - for { - if r := C.AttachConsole(processID); r != 0 { - break // success - } - lastError := C.GetLastError() - if lastError != C.ERROR_GEN_FAILURE || count <= 0 { - return fmt.Errorf("Was not able to attach to the child prosess' console") - } - - time.Sleep(time.Millisecond * time.Duration(waitStepMilliSeconds)) - count-- - } - - h := C.GetStdHandle(nStdHandle) - C.SetConsoleMode(h, C.DWORD(mode)) - C.FreeConsole() - - return nil + return process, nil } func (pty *winConPty) Resize(x, y int) error {