-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
55 lines (44 loc) · 1.2 KB
/
commands.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
package main
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"log"
"os/exec"
"path/filepath"
"strings"
)
// unzipFile run the command gunzip
// return the fileName without the extension
func unzipFile(fileName string) (string, error) {
log.Println("Command::", append([]string{gunzipCMD}, fileName))
cmd := exec.Command(gunzipCMD, fileName)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return "", errors.New(fmt.Sprint(err) + ": " + stderr.String())
}
return strings.TrimSuffix(fileName, filepath.Ext(fileName)), nil
}
// processFilesWithTeqc run the command teqc
// and create a file example.obs
func processFilesWithTeqc(fileNames []string, baseStationID string) error {
name := baseStationID + ".obs"
cmdArgs := fileNames
cmdArgs = append(cmdArgs, ">")
cmdArgs = append(cmdArgs, name)
log.Println("Command::", append([]string{teqcCMD}, cmdArgs...))
cmd := exec.Command(teqcCMD, cmdArgs...)
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Start(); err != nil {
return err
}
if err := cmd.Wait(); err != nil {
log.Printf("Error:%v", err)
}
return ioutil.WriteFile("./"+name, stdout.Bytes(), 0644)
}