exec一个golang包用于与一个在后台运行的进程进行交互
exec一个golang包用于与一个在后台运行的进程进行交互
Go 工具类
共10Star
详细介绍
exec
A golang package to interact with a process running in background
Example
package main
import (
"fmt"
"time"
"github.com/adlane/exec"
)
func main() {
ctx := exec.InteractiveExec("bash", "-i")
r := reader{}
go ctx.Receive(&r, 5*time.Second)
ctx.Send("echo hello world\n")
time.Sleep(time.Second)
ctx.Send("ls\n")
time.Sleep(time.Second)
}
type reader struct {
}
func (*reader) OnData(b []byte) bool {
fmt.Print(string(b))
return false
}
func (*reader) OnError(b []byte) bool {
fmt.Print(string(b))
return false
}
func (*reader) OnTimeout() {}
Output
$ echo hello world
hello world
$ ls
bash.go
cat-random.go