adlane / exec

A golang package to interact with a process running in background

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoDoc

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 

About

A golang package to interact with a process running in background

License:Apache License 2.0


Languages

Language:Go 100.0%