diff --git a/wox.core/plugin/host/host_websocket.go b/wox.core/plugin/host/host_websocket.go index af4a28176..ce3cfc977 100644 --- a/wox.core/plugin/host/host_websocket.go +++ b/wox.core/plugin/host/host_websocket.go @@ -3,6 +3,7 @@ package host import ( "context" "encoding/json" + "errors" "fmt" "os" "strings" @@ -135,7 +136,7 @@ func (w *WebsocketHost) invokeMethod(ctx context.Context, metadata plugin.Metada case response := <-resultChan: util.GetLogger().Debug(ctx, fmt.Sprintf("inovke plugin <%s> method: %s finished, response time: %dms", metadata.Name, method, util.GetSystemTimestamp()-startTimestamp)) if response.Error != "" { - return "", fmt.Errorf(response.Error) + return "", errors.New(response.Error) } else { return response.Result, nil } diff --git a/wox.core/util/open_linux.go b/wox.core/util/open_linux.go index 5fcc3b95a..a15461fb8 100644 --- a/wox.core/util/open_linux.go +++ b/wox.core/util/open_linux.go @@ -1,6 +1,9 @@ package util -import "os/exec" +import ( + "os" + "os/exec" +) func ShellOpen(path string) error { return exec.Command("xdg-open", path).Start() @@ -18,6 +21,23 @@ func ShellRun(name string, arg ...string) (*exec.Cmd, error) { return cmd, nil } +func ShellRunWithEnv(name string, envs []string, arg ...string) (*exec.Cmd, error) { + if len(envs) == 0 { + return ShellRun(name, arg...) + } + + cmd := exec.Command(name, arg...) + cmd.Stdout = GetLogger().GetWriter() + cmd.Stderr = GetLogger().GetWriter() + cmd.Env = append(os.Environ(), envs...) + cmdErr := cmd.Start() + if cmdErr != nil { + return nil, cmdErr + } + + return cmd, nil +} + func ShellRunOutput(name string, arg ...string) ([]byte, error) { cmd := exec.Command(name, arg...) return cmd.Output() diff --git a/wox.core/util/open_windows.go b/wox.core/util/open_windows.go index 3da1c25bb..bf63ec4b7 100644 --- a/wox.core/util/open_windows.go +++ b/wox.core/util/open_windows.go @@ -25,6 +25,23 @@ func ShellRun(name string, arg ...string) (*exec.Cmd, error) { return cmd, nil } +func ShellRunWithEnv(name string, envs []string, arg ...string) (*exec.Cmd, error) { + if len(envs) == 0 { + return ShellRun(name, arg...) + } + + cmd := exec.Command(name, arg...) + cmd.Stdout = GetLogger().GetWriter() + cmd.Stderr = GetLogger().GetWriter() + cmd.Env = append(os.Environ(), envs...) + cmdErr := cmd.Start() + if cmdErr != nil { + return nil, cmdErr + } + + return cmd, nil +} + func ShellRunOutput(name string, arg ...string) ([]byte, error) { cmd := exec.Command(name, arg...) cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Hide the window