forked from gopherdata/gophernotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagic.go
More file actions
30 lines (27 loc) · 635 Bytes
/
Copy pathmagic.go
File metadata and controls
30 lines (27 loc) · 635 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
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func eval_magic(codes []string) {
tpLine := strings.Trim(codes[0], "%")
if strings.HasPrefix(tpLine, "bash") {
bashCode := strings.Join(codes[1:], "\n")
cmd := exec.Command("sh", "-c", bashCode)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
} else if strings.HasPrefix(tpLine, "put") {
args := strings.Split(tpLine, "put")
if len(args) <= 1 {
return
}
cmd := fmt.Sprintf("hadoop fs -put %s hdfs://172.29.15.131:8020/h2o/%s", args[1], os.Getenv("USER"))
c := exec.Command(cmd)
c.Stdout = os.Stdout
c.Stderr = os.Stderr
c.Run()
}
}