Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646606680 and https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646594105
This commit is contained in:
parent
7fddd4d073
commit
ce15213009
3 changed files with 117 additions and 3 deletions
|
@ -112,6 +112,28 @@ func Clear() {
|
|||
_ = c.Run()
|
||||
}
|
||||
|
||||
func processCmdString(cmd string) (string, []string) {
|
||||
// handle quoted arguments
|
||||
args := strings.Fields(cmd)
|
||||
cmdBin := args[0]
|
||||
args = args[1:]
|
||||
for i, arg := range args {
|
||||
if !strings.HasPrefix(arg, "\"") {
|
||||
continue
|
||||
}
|
||||
// find the end of the quoted argument
|
||||
for j, a := range args[i:] {
|
||||
if strings.HasSuffix(a, "\"") {
|
||||
args[i] = strings.Join(args[i:i+j+1], " ")
|
||||
args = append(args[:i+1], args[i+j+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cmdBin, args
|
||||
}
|
||||
|
||||
// ExecAndLogSudo executes an elevated command and logs the output.
|
||||
//
|
||||
// * if we're root, the command is executed directly
|
||||
|
@ -138,8 +160,8 @@ func ExecAndLogSudo(isRoot, noisy bool, cmd string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cs := strings.Fields(cmd)
|
||||
r := exec.Command(cs[0], cs[1:]...)
|
||||
cmdBin, args := processCmdString(cmd)
|
||||
r := exec.Command(cmdBin, args...)
|
||||
r.Dir = wd
|
||||
|
||||
cmdCombinedOut, err := r.CombinedOutput()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue