-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
util.go
47 lines (42 loc) · 630 Bytes
/
util.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
//go:build windows
// +build windows
package main
import (
"encoding/gob"
"io"
"syscall"
)
type msg struct {
Name string
Exit int
Error string
Data []byte
}
func msgWrite(enc *gob.Encoder, typ string) io.WriteCloser {
r, w := io.Pipe()
go func() {
defer r.Close()
var b [4096]byte
for {
n, err := r.Read(b[:])
if err != nil {
break
}
err = enc.Encode(&msg{Name: typ, Data: b[:n]})
if err != nil {
break
}
}
}()
return w
}
func makeCmdLine(args []string) string {
var s string
for _, v := range args {
if s != "" {
s += " "
}
s += syscall.EscapeArg(v)
}
return s
}