33 lines
538 B
Go
33 lines
538 B
Go
|
|
//go:build windows
|
||
|
|
|
||
|
|
package starssh
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
|
||
|
|
"golang.org/x/sys/windows"
|
||
|
|
)
|
||
|
|
|
||
|
|
func duplicateTerminalInputFile(file *os.File) (*os.File, error) {
|
||
|
|
if file == nil {
|
||
|
|
return nil, os.ErrInvalid
|
||
|
|
}
|
||
|
|
|
||
|
|
currentProcess := windows.CurrentProcess()
|
||
|
|
var duplicated windows.Handle
|
||
|
|
err := windows.DuplicateHandle(
|
||
|
|
currentProcess,
|
||
|
|
windows.Handle(file.Fd()),
|
||
|
|
currentProcess,
|
||
|
|
&duplicated,
|
||
|
|
0,
|
||
|
|
false,
|
||
|
|
windows.DUPLICATE_SAME_ACCESS,
|
||
|
|
)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return os.NewFile(uintptr(duplicated), file.Name()), nil
|
||
|
|
}
|