Update exec.Command on all OSes

This commit is contained in:
Tulir Asokan 2020-10-24 15:35:40 +03:00
parent 3cac79a274
commit 114940eef6
4 changed files with 19 additions and 34 deletions

View File

@ -1,5 +1,3 @@
// +build !windows,!darwin
// gomuks - A terminal Matrix client written in Go. // gomuks - A terminal Matrix client written in Go.
// Copyright (C) 2020 Tulir Asokan // Copyright (C) 2020 Tulir Asokan
// //
@ -20,16 +18,22 @@ package open
import ( import (
"os/exec" "os/exec"
"maunium.net/go/gomuks/debug" "maunium.net/go/gomuks/debug"
) )
func Open(input string) error { func Open(input string) error {
cmd := exec.Command("xdg-open", input) cmd := exec.Command(Command, append(Args, input)...)
err := cmd.Start() err := cmd.Start()
if err != nil { if err != nil {
debug.Print("xdg-open error:", err) debug.Printf("Failed to start %s: %v", Command, err)
} else { } else {
go cmd.Wait() go func() {
waitErr := cmd.Wait()
if waitErr != nil {
debug.Printf("Failed to run %s: %v", Command, err)
}
}()
} }
return err return err
} }

View File

@ -1,25 +1,4 @@
// gomuks - A terminal Matrix client written in Go.
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package open package open
import ( const Command = "open"
"os/exec" var Args []string
)
func Open(input string) error {
return exec.Command("open", input).Start()
}

View File

@ -18,14 +18,10 @@ package open
import ( import (
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
) )
const FileProtocolHandler = "url.dll,FileProtocolHandler" const FileProtocolHandler = "url.dll,FileProtocolHandler"
var RunDLL32 = filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "rundll32.exe") var Command = filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "rundll32.exe")
var Args = []string{FileProtocolHandler}
func Open(input string) error {
return exec.Command(RunDLL32, FileProtocolHandler, input).Start()
}

6
lib/open/open_xdg.go Normal file
View File

@ -0,0 +1,6 @@
// +build !windows,!darwin
package open
const Command = "xdg-open"
var Args []string