Last active
February 23, 2024 16:50
-
-
Save technicalpickles/d37b91fc9f43ae258d0afb136e71add3 to your computer and use it in GitHub Desktop.
Revisions
-
technicalpickles revised this gist
Feb 23, 2024 . No changes.There are no files selected for viewing
-
technicalpickles renamed this gist
Feb 23, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
technicalpickles created this gist
Feb 23, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ package main import ( "context" "io" "os" "os/exec" "github.com/creack/pty" ) // internal/lefthooik/run/exec/execute_unix.go type executeArgs struct { in io.Reader out io.Writer envs []string root string interactive, useStdin bool } func main() { ctx := context.Background() // internal/lefthook/run.go Lefthook.Run // ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) // defer stop() // https://yourbasic.org/golang/log-to-file/ in, err := os.OpenFile("/dev/null", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { println(err.Error()) } defer in.Close() // internal/lefthooik/run/exec/execute_unix.go command := exec.CommandContext(ctx, "sh", "-c", "sleep 2") command.Stdin = in wd, err := os.Getwd() if err != nil { panic(err) } command.Dir = wd command.Env = os.Environ() p, err := pty.Start(command) if err != nil { panic(err) } defer func() { _ = p.Close() }() command.Wait() }