-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
launch.go
49 lines (40 loc) · 916 Bytes
/
launch.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
package server
import (
"fmt"
"io"
"os"
"time"
"os/exec"
"github.com/creack/pty"
)
type launchedProcess struct {
command *exec.Cmd
stdin io.WriteCloser
stdout io.ReadCloser
stderr io.ReadCloser
tty *os.File
}
func record(actionName, commandName string, args []string, env []string) (*launchedProcess, error) {
newName := "ttyrec"
outfile := fmt.Sprintf("history/%s-%d.ttyrec", actionName, time.Now().Unix())
newArgs := []string{
"-f",
outfile,
"--",
commandName,
}
newArgs = append(newArgs, args...)
return launch(actionName, newName, newArgs, env)
}
func launch(actionName, commandName string, commandArgs []string, env []string) (*launchedProcess, error) {
command := exec.Command(commandName, commandArgs...)
command.Env = env
tty, err := pty.Start(command)
if err != nil {
return nil, err
}
return &launchedProcess{
command: command,
tty: tty,
}, err
}