Last active
September 15, 2023 14:58
-
-
Save williammartin/06767ceb8aa6dc21b0609b268c2ed46c to your computer and use it in GitHub Desktop.
hijack.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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