Skip to content
/ exec Public

A golang package to interact with a process running in background

License

Notifications You must be signed in to change notification settings

adlane/exec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages