mirror of https://github.com/mickael-menu/zk
Add a cross-platform way to execute a shell command and string utilities
parent
cd2040a74b
commit
f1df4320ed
@ -0,0 +1,3 @@
|
||||
// +build !windows
|
||||
|
||||
package exec
|
@ -0,0 +1,17 @@
|
||||
// +build !windows
|
||||
|
||||
package exec
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// CommandFromString returns a Cmd running the given command with $SHELL.
|
||||
func CommandFromString(command string) *exec.Cmd {
|
||||
shell := os.Getenv("SHELL")
|
||||
if len(shell) == 0 {
|
||||
shell = "sh"
|
||||
}
|
||||
return exec.Command(shell, "-c", command)
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package exec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// CommandFromString returns a Cmd running the given command.
|
||||
func CommandFromString(command string) *exec.Cmd {
|
||||
cmd := exec.Command("cmd")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
HideWindow: false,
|
||||
CmdLine: fmt.Sprintf(` /v:on/s/c "%s"`, command),
|
||||
CreationFlags: 0,
|
||||
}
|
||||
return cmd
|
||||
}
|
Loading…
Reference in New Issue