summaryrefslogtreecommitdiff
path: root/posix.go
diff options
context:
space:
mode:
Diffstat (limited to 'posix.go')
-rw-r--r--posix.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/posix.go b/posix.go
new file mode 100644
index 0000000..38a1c50
--- /dev/null
+++ b/posix.go
@@ -0,0 +1,95 @@
+package shell
+
+// old code and probably junk
+
+import (
+ "os"
+ "os/exec"
+
+ "go.wit.com/log"
+)
+
+// 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
+// var shellStderr *os.File
+
+// var spewOn bool = false
+// var quiet bool = false
+
+// var msecDelay int = 20 // number of milliseconds to delay between reads with no data
+
+// var bytesBuffer bytes.Buffer
+// var bytesSplice []byte
+
+func handleError(c interface{}, ret int) {
+ log.Log(INFO, "shell.Run() Returned", ret)
+ if callback != nil {
+ callback(c, ret)
+ }
+}
+
+func init() {
+ callback = nil
+}
+
+func InitCallback(f func(interface{}, int)) {
+ callback = f
+}
+
+func Unlink(filename string) bool {
+ if err := os.Remove(filename); err != nil {
+ return Exists(filename)
+ } else {
+ return Exists(filename)
+ }
+}
+
+// run interactively. output from the cmd is in real time
+// shows all the output. For example, 'ping -n localhost'
+// shows the output like you would expect to see
+func RunSimple(cmd []string) error {
+ log.Log(INFO, "NewRun() ", cmd)
+
+ return PathRunSimple("", cmd)
+}
+
+func PathRunSimple(workingpath string, cmd []string) error {
+ log.Log(INFO, "NewRun() ", cmd)
+
+ process := exec.Command(cmd[0], cmd[1:len(cmd)]...)
+ // Set the working directory
+ process.Dir = workingpath
+ process.Stderr = os.Stderr
+ process.Stdin = os.Stdin
+ process.Stdout = os.Stdout
+ process.Start()
+ err := process.Wait()
+ if err != nil {
+ log.Log(INFO, "shell.Exec() err =", err)
+ }
+ return err
+}
+
+// return true if the filename exists (cross-platform)
+
+// return true if the filename exists (cross-platform)
+func Exists(filename string) bool {
+ _, err := os.Stat(Path(filename))
+ if os.IsNotExist(err) {
+ return false
+ }
+ return true
+}
+
+// return true if the filename exists (cross-platform)
+func IsDir(dirname string) bool {
+ info, err := os.Stat(Path(dirname))
+ if os.IsNotExist(err) {
+ return false
+ }
+ return info.IsDir()
+}