summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2019-06-09 14:29:50 -0700
committerJeff Carr <[email protected]>2019-06-09 14:29:50 -0700
commit4736714c08ac85276806ea6c6a584fb7993d0053 (patch)
tree192d46d612fd4f72ab5da0a98fd06b9d1f3cc222
parentdf1460aa69a85d23a42a81d6ca3108ff6dfaf6f6 (diff)
add shell.Exec() to execute and never return
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--shell.go19
-rw-r--r--wget.go2
2 files changed, 21 insertions, 0 deletions
diff --git a/shell.go b/shell.go
index c5b4d8b..47ff9ed 100644
--- a/shell.go
+++ b/shell.go
@@ -16,6 +16,9 @@ import "github.com/svent/go-nbreader"
import log "github.com/sirupsen/logrus"
// import "github.com/wercker/journalhook"
+// TODO: look at https://github.com/go-cmd/cmd/issues/20
+// use go-cmd instead here?
+
var callback func(interface{}, int)
var shellStdout *os.File
@@ -251,3 +254,19 @@ func nonBlockingReader(buffReader *bufio.Reader, writeFileHandle *os.File, stdou
}
}
}
+
+// run something and never return from it
+// TODO: pass STDOUT, STDERR, STDIN correctly
+// TODO: figure out how to nohup the process and exit
+func Exec(cmdline string) {
+ log.Println("shell.Run() START " + cmdline)
+
+ cmd := Chomp(cmdline) // this is like 'chomp' in perl
+ cmdArgs := strings.Fields(cmd)
+
+ process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
+ process.Start()
+ err := process.Wait()
+ log.Println("shell.Exec() err =", err)
+ os.Exit(0)
+}
diff --git a/wget.go b/wget.go
index a2317c4..5d5c1be 100644
--- a/wget.go
+++ b/wget.go
@@ -45,6 +45,8 @@ func Wget(url string) (*bytes.Buffer) {
}
func WgetToFile(filepath string, url string) error {
+ log.Println("WgetToFile() filepath =", filepath)
+ log.Println("WgetToFile() URL =", url)
// Get the data
resp, err := http.Get(url)
if err != nil {