https://github.com/userexistserror/conpty
Windows Pseudo Console (ConPTY) for Golang
https://github.com/userexistserror/conpty
Last synced: 5 months ago
JSON representation
Windows Pseudo Console (ConPTY) for Golang
- Host: GitHub
- URL: https://github.com/userexistserror/conpty
- Owner: UserExistsError
- License: mit
- Created: 2020-09-07T18:42:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-09T18:43:02.000Z (over 1 year ago)
- Last Synced: 2025-06-15T23:04:36.644Z (8 months ago)
- Language: Go
- Size: 11.7 KB
- Stars: 33
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# conpty
Windows Pseudo Console (ConPTY) for Golang
See:
https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/
## Usage
```go
package main
import (
"context"
"io"
"log"
"os"
"github.com/UserExistsError/conpty"
)
func main() {
commandLine := `c:\windows\system32\cmd.exe`
cpty, err := conpty.Start(commandLine)
if err != nil {
log.Fatalf("Failed to spawn a pty: %v", err)
}
defer cpty.Close()
go io.Copy(os.Stdout, cpty)
go io.Copy(cpty, os.Stdin)
exitCode, err := cpty.Wait(context.Background())
if err != nil {
log.Fatalf("Error: %v", err)
}
log.Printf("ExitCode: %d", exitCode)
}
```