-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinteractor.go
More file actions
47 lines (39 loc) · 913 Bytes
/
Copy pathinteractor.go
File metadata and controls
47 lines (39 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"bytes"
"fmt"
"io"
"github.com/iamalsaher/interactor/pkg/process"
)
func interactor(input io.Writer, output io.Reader, closer chan bool) {
var b bytes.Buffer
b.Grow(8192)
go io.Copy(&b, output)
go input.Write([]byte("Swapnil\r\n"))
for {
select {
case <-closer:
// fmt.Print(string(b.Bytes()))
return
default:
if b.Len() > 0 {
fmt.Print(string(b.Next(b.Len())))
}
}
}
}
func main() {
proc := process.NewProcess(`.\binary.exe`, "--tty", "--sleep", "2", "--input")
// proc.SetEnviron([]string{"SEXYENV=LOL"}, true)
// proc.SetDirectory("/tmp")
// proc.SetTimeout(1 * time.Second)
if e := proc.ConnectIO(true); e != nil {
panic(e)
}
if e := proc.Start(); e != nil {
panic(e)
}
fmt.Printf("Started Process with PID %v\n", proc.PID)
interactor(proc.Stdin, proc.Stdout, proc.Done)
fmt.Printf("exit code was: %d\n", proc.State.ExitCode())
}