2020-01-09 06:17:39 -05:00
|
|
|
// +build !windows,!darwin
|
|
|
|
|
2020-01-19 06:57:05 -05:00
|
|
|
package zenutil
|
2020-01-09 06:17:39 -05:00
|
|
|
|
|
|
|
import (
|
2020-01-28 07:46:43 -05:00
|
|
|
"context"
|
2020-01-09 06:17:39 -05:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2020-01-28 07:46:43 -05:00
|
|
|
"strconv"
|
2020-01-09 06:17:39 -05:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
var tool, path string
|
|
|
|
|
|
|
|
func init() {
|
2020-01-09 21:14:50 -05:00
|
|
|
for _, tool = range [3]string{"qarma", "zenity", "matedialog"} {
|
2020-01-09 06:17:39 -05:00
|
|
|
path, _ = exec.LookPath(tool)
|
|
|
|
if path != "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tool = "zenity"
|
|
|
|
}
|
|
|
|
|
2020-01-28 07:46:43 -05:00
|
|
|
func Run(ctx context.Context, args []string) ([]byte, error) {
|
2020-01-19 06:57:05 -05:00
|
|
|
if Command && path != "" {
|
2020-01-28 07:46:43 -05:00
|
|
|
if Timeout > 0 {
|
|
|
|
args = append(args, "--timeout", strconv.Itoa(Timeout))
|
|
|
|
}
|
2020-01-09 06:17:39 -05:00
|
|
|
syscall.Exec(path, append([]string{tool}, args...), os.Environ())
|
|
|
|
}
|
2020-01-28 07:46:43 -05:00
|
|
|
|
|
|
|
if ctx != nil {
|
|
|
|
return exec.CommandContext(ctx, tool, args...).Output()
|
|
|
|
}
|
2020-01-09 06:17:39 -05:00
|
|
|
return exec.Command(tool, args...).Output()
|
|
|
|
}
|