diff --git a/cointop/common/open/open.go b/cointop/common/open/open.go index b64c965..7f875d4 100644 --- a/cointop/common/open/open.go +++ b/cointop/common/open/open.go @@ -37,9 +37,9 @@ func init() { } // URL open url -func URL(s string) error { +func URL(url string) error { if openCmd != "" { - exec.Command(openCmd, s).Output() + return exec.Command(openCmd, url).Run() } return nil } diff --git a/cointop/common/open/open_win.go b/cointop/common/open/open_win.go deleted file mode 100644 index ca80ed0..0000000 --- a/cointop/common/open/open_win.go +++ /dev/null @@ -1,52 +0,0 @@ -package open - -import ( - "os/exec" -) - -var openCmd string -var possibleCmds = []string{ - "Start-Process", // windows -} - -var possibleShells = []string{ - "powershell.exe", - "explorer.exe", -} - -var mainShell string - -func init() { - for _, sh := range possibleShells { - shell, err := exec.LookPath(sh) - if err != nil { - continue - } - - mainShell = shell - break - } - - for _, cmd := range possibleCmds { - err := exec.Command(mainShell, "Get-Command", cmd).Run() - if err != nil { - continue - } - - openCmd = cmd - break - } -} - -// URL open url -func URL(s string) error { - if openCmd != "" { - return exec.Command(mainShell, openCmd, s).Run() - } - return nil -} - -// CommandExists returns true if an 'open' command exists -func CommandExists() bool { - return openCmd != "" -} diff --git a/cointop/common/open/open_windows.go b/cointop/common/open/open_windows.go new file mode 100644 index 0000000..5921356 --- /dev/null +++ b/cointop/common/open/open_windows.go @@ -0,0 +1,50 @@ +package open + +import ( + "os/exec" +) + +var windowsOpenCmd string +var windowsPossibleCmds = []string{ + "Start-Process", +} +var windowsPossibleExecs = []string{ + "powershell.exe", + "explorer.exe", +} +var windowsOpenExec string + +func init() { + for _, exe := range windowsPossibleExecs { + execPath, err := exec.LookPath(exe) + if err != nil { + continue + } + + windowsOpenExec = execPath + break + } + + for _, cmd := range windowsPossibleCmds { + err := exec.Command(windowsOpenExec, "Get-Command", cmd).Run() + if err != nil { + continue + } + + windowsOpenCmd = cmd + break + } +} + +// URL open url +func URL(url string) error { + if windowsOpenCmd != "" { + return exec.Command(windowsOpenExec, windowsOpenCmd, url).Run() + } + return nil +} + +// CommandExists returns true if an 'open' command exists +func CommandExists() bool { + return windowsOpenCmd != "" +}