Skip to content

Instantly share code, notes, and snippets.

@williammartin
Last active September 15, 2023 14:58
Show Gist options
  • Save williammartin/06767ceb8aa6dc21b0609b268c2ed46c to your computer and use it in GitHub Desktop.
Save williammartin/06767ceb8aa6dc21b0609b268c2ed46c to your computer and use it in GitHub Desktop.
hijack.go
package main
import (
"fmt"
"io"
"os/exec"
"syscall"
"github.com/creack/pty"
)
func main() {
ptm, pty, err := pty.Open()
if err != nil {
panic(err)
}
cmd := exec.Command("asciinema", "rec", "-q", "-c", "lsof -p $$", "--overwrite", "showing")
cmd.Stdin = pty
cmd.Stdout = pty
cmd.Stderr = pty
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
Setctty: true,
Ctty: 3,
}
cmd.ExtraFiles = append(cmd.ExtraFiles, pty)
fmt.Println("running")
go func() { _, _ = io.Copy(io.Discard, ptm) }()
err = cmd.Run()
if err != nil {
// _, _ = io.Copy(os.Stderr, ptm)
panic(err)
}
fmt.Println("run")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment