-
Notifications
You must be signed in to change notification settings - Fork 160
/
std.go
94 lines (85 loc) · 2.1 KB
/
std.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2013 The Go Circuit Project
// Use of this source code is governed by the license for
// The Go Circuit Project, found in the LICENSE file.
//
// Authors:
// 2013 Petar Maymounkov <p@gocircuit.org>
package main
import (
"io"
"os"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
func stdin(x *cli.Context) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.Wrapf(r.(error), "error, likely due to missing server or misspelled anchor: %v", r)
}
}()
c := dial(x)
args := x.Args()
if len(args) != 1 {
return errors.New("stdin needs one anchor argument")
}
w, _ := parseGlob(args[0])
u, ok := c.Walk(w).Get().(interface {
Stdin() io.WriteCloser
})
if !ok {
return errors.New("not a process or a container")
}
q := u.Stdin()
if _, err = io.Copy(q, os.Stdin); err != nil {
return errors.Wrapf(err, "transmission error: %v", err)
}
if err = q.Close(); err != nil {
return errors.Wrapf(err, "error closing stdin: %v", err)
}
return
}
func stdout(x *cli.Context) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.Wrapf(r.(error), "error, likely due to missing server or misspelled anchor: %v", r)
}
}()
c := dial(x)
args := x.Args()
if len(args) != 1 {
return errors.New("stdout needs one anchor argument")
}
w, _ := parseGlob(args[0])
u, ok := c.Walk(w).Get().(interface {
Stdout() io.ReadCloser
})
if !ok {
return errors.New("not a process or a container")
}
io.Copy(os.Stdout, u.Stdout())
return
}
func stderr(x *cli.Context) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.Wrapf(r.(error), "error, likely due to missing server or misspelled anchor: %v", r)
}
}()
c := dial(x)
args := x.Args()
if len(args) != 1 {
return errors.New("stderr needs one anchor argument")
}
w, _ := parseGlob(args[0])
u, ok := c.Walk(w).Get().(interface {
Stderr() io.ReadCloser
})
if !ok {
return errors.New("not a process or a container")
}
io.Copy(os.Stdout, u.Stderr())
// if _, err := io.Copy(os.Stdout, u.Stderr()); err != nil {
// fatalf("transmission error: %v", err)
// }
return
}