mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 04:52:10 -07:00
50 lines
828 B
Go
50 lines
828 B
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"sort"
|
|
|
|
"github.com/evilsocket/islazy/str"
|
|
)
|
|
|
|
func UniqueInts(a []int, sorted bool) []int {
|
|
tmp := make(map[int]bool)
|
|
uniq := make([]int, 0)
|
|
|
|
for _, n := range a {
|
|
tmp[n] = true
|
|
}
|
|
|
|
for n := range tmp {
|
|
uniq = append(uniq, n)
|
|
}
|
|
|
|
if sorted {
|
|
sort.Ints(uniq)
|
|
}
|
|
|
|
return uniq
|
|
}
|
|
|
|
func ExecSilent(executable string, args []string) (string, error) {
|
|
path, err := exec.LookPath(executable)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
raw, err := exec.Command(path, args...).CombinedOutput()
|
|
if err != nil {
|
|
return "", err
|
|
} else {
|
|
return str.Trim(string(raw)), nil
|
|
}
|
|
}
|
|
|
|
func Exec(executable string, args []string) (string, error) {
|
|
out, err := ExecSilent(executable, args)
|
|
if err != nil {
|
|
fmt.Printf("ERROR for '%s %s': %s\n", executable, args, err)
|
|
}
|
|
return out, err
|
|
}
|