RunEcho()
This commit is contained in:
parent
99eded5398
commit
8d692299b0
8
Makefile
8
Makefile
|
@ -1,5 +1,9 @@
|
||||||
all:
|
all: goimports vet
|
||||||
GO111MODULE=off go build
|
|
||||||
|
vet:
|
||||||
|
@GO111MODULE=off go vet
|
||||||
|
@echo this go library package builds okay
|
||||||
|
|
||||||
|
|
||||||
goimports:
|
goimports:
|
||||||
goimports -w *.go
|
goimports -w *.go
|
||||||
|
|
40
cmd.go
40
cmd.go
|
@ -2,7 +2,7 @@ package shell
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-cmd/cmd"
|
"github.com/go-cmd/cmd"
|
||||||
|
@ -139,6 +139,21 @@ func RunRealtime(args []string) cmd.Status {
|
||||||
return PathRunRealtime("", args)
|
return PathRunRealtime("", args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RunEcho(cmd []string) cmd.Status {
|
||||||
|
result := RunQuiet(cmd)
|
||||||
|
pwd, _ := os.Getwd()
|
||||||
|
log.Warn("shell.RunEcho() cmd:", cmd, pwd)
|
||||||
|
log.Warn("shell.RunEcho() Exit:", result.Exit)
|
||||||
|
log.Warn("shell.RunEcho() Error:", result.Error)
|
||||||
|
for _, line := range result.Stdout {
|
||||||
|
log.Warn("STDOUT:", line)
|
||||||
|
}
|
||||||
|
for _, line := range result.Stderr {
|
||||||
|
log.Warn("STDERR:", line)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// echos twice a second if anything sends to STDOUT or STDERR
|
// echos twice a second if anything sends to STDOUT or STDERR
|
||||||
// not great, but it's really just for watching things run in real time anyway
|
// not great, but it's really just for watching things run in real time anyway
|
||||||
// TODO: fix \r handling for things like git-clone so the terminal doesn't
|
// TODO: fix \r handling for things like git-clone so the terminal doesn't
|
||||||
|
@ -210,29 +225,8 @@ func PathRunRealtime(pwd string, args []string) cmd.Status {
|
||||||
|
|
||||||
// Block waiting for command to exit, be stopped, or be killed
|
// Block waiting for command to exit, be stopped, or be killed
|
||||||
finalStatus := <-statusChan
|
finalStatus := <-statusChan
|
||||||
|
log.Info("shell.Run() notsure finalStatus", finalStatus.Cmd)
|
||||||
return findCmd.Status()
|
return findCmd.Status()
|
||||||
return finalStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
func blah(cmd []string) {
|
|
||||||
r := Run(cmd)
|
|
||||||
log.Info("cmd =", r.Cmd)
|
|
||||||
log.Info("complete =", r.Complete)
|
|
||||||
log.Info("exit =", r.Exit)
|
|
||||||
log.Info("err =", r.Error)
|
|
||||||
log.Info("len(stdout+stderr) =", len(r.Stdout))
|
|
||||||
}
|
|
||||||
|
|
||||||
// run these to see confirm the sytem behaves as expected
|
|
||||||
func RunTest() {
|
|
||||||
blah([]string{"ping", "-c", "3", "localhost"})
|
|
||||||
blah([]string{"exit", "0"})
|
|
||||||
blah([]string{"exit", "-1"})
|
|
||||||
blah([]string{"true"})
|
|
||||||
blah([]string{"false"})
|
|
||||||
blah([]string{"grep", "root", "/etc/", "/proc/cmdline", "/usr/bin/chmod"})
|
|
||||||
blah([]string{"grep", "root", "/proc/cmdline"})
|
|
||||||
fmt.Sprint("blahdone")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is stuff from a long time ago that there must be a replacement for
|
// this is stuff from a long time ago that there must be a replacement for
|
||||||
|
|
2
wget.go
2
wget.go
|
@ -34,7 +34,7 @@ func Wget(url string) *bytes.Buffer {
|
||||||
|
|
||||||
log.Log(INFO, "res.StatusCode: %d\n", resp.StatusCode)
|
log.Log(INFO, "res.StatusCode: %d\n", resp.StatusCode)
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
handleError(fmt.Errorf(fmt.Sprint("%d", resp.StatusCode)), -1)
|
handleError(fmt.Errorf(fmt.Sprintf("%d", resp.StatusCode)), -1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
xterm.go
19
xterm.go
|
@ -8,6 +8,21 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// not sure why I wrote this or what it is for
|
||||||
|
// this is because I'm crazy. how crazy you ask? fucking crazy!
|
||||||
|
// hehe. If you haven't ever written code that you look back
|
||||||
|
// at like this and go 'what the fuck is this shit', then
|
||||||
|
// realize that you wrote it, then go 'what the fuck is this shit'
|
||||||
|
// and then still look at it and wonder, "how early was this. how much did I not know when I wrote this"
|
||||||
|
// then, if you haven't done those kinds of things, then don't
|
||||||
|
// ever fucking come up to me and tell me that I'm nuts
|
||||||
|
// because, you are not as good as me then. It's very complicated
|
||||||
|
// to work on very complicated things. I don't care how smart you are,
|
||||||
|
// you can totally forget about shit you wrote and then have to come back to it later
|
||||||
|
|
||||||
|
// also, what the fuck was I thinking with the function 'scanToParent()' as a function that takes
|
||||||
|
// a pid arg? what? is this like pstree? I'm not sure what I wanted this for
|
||||||
|
// but it sounds interesting.
|
||||||
func scanToParent(pid int) (bool, string) {
|
func scanToParent(pid int) (bool, string) {
|
||||||
ppid, err := GetPPID(pid)
|
ppid, err := GetPPID(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,8 +50,6 @@ func scanToParent(pid int) (bool, string) {
|
||||||
case "make":
|
case "make":
|
||||||
// keep digging for the parent xterm
|
// keep digging for the parent xterm
|
||||||
return scanToParent(ppid)
|
return scanToParent(ppid)
|
||||||
default:
|
|
||||||
return false, comm
|
|
||||||
}
|
}
|
||||||
if comm == "bash" {
|
if comm == "bash" {
|
||||||
}
|
}
|
||||||
|
@ -81,8 +94,6 @@ func Shell() string {
|
||||||
switch envsh {
|
switch envsh {
|
||||||
case "/bin/bash":
|
case "/bin/bash":
|
||||||
return "bash"
|
return "bash"
|
||||||
default:
|
|
||||||
return envsh
|
|
||||||
}
|
}
|
||||||
return envsh
|
return envsh
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue