-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfork.go
67 lines (60 loc) · 979 Bytes
/
fork.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"bytes"
"flag"
"io"
"log"
"os"
"github.com/pipes-and-filters/filters"
)
var (
chainsFile string
)
func init() {
flag.StringVar(
&chainsFile,
"chains",
"",
"Chains file for forking process.",
)
}
func main() {
flag.Parse()
if chainsFile == "" {
log.Fatal("No chains file specified")
}
cs, err := filters.ChainsFile(chainsFile)
if err != nil {
log.Fatal(err)
}
var main filters.Chain
main, err = cs.Get("Main")
if err != nil {
log.Fatal(err)
}
var fork filters.Chain
fork, err = cs.Get("Fork")
if err != nil {
log.Fatal(err)
}
maine, err := main.Exec()
if err != nil {
log.Fatal(err)
}
forke, err := fork.Exec()
if err != nil {
log.Fatal(err)
}
var forki bytes.Buffer
maini := io.TeeReader(os.Stdin, &forki)
maine.SetInput(maini)
maine.SetOutput(os.Stdout)
forke.SetOutput(os.Stdout)
forke.SetInput(&forki)
forke.Detach()
go forke.Run()
err = maine.Run()
if err != nil {
log.Fatal(err)
}
}