Skip to content

Commit f917aea

Browse files
authored
Merge pull request #193 from janog-netcon/fix-exec
Parse execCommand to do command including space
2 parents cc8c9d7 + f84f636 commit f917aea

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cmd/access-helper/exec.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67
"os/exec"
78

9+
"github.com/google/shlex"
810
"github.com/janog-netcon/netcon-problem-management-subsystem/pkg/containerlab"
911
)
1012

@@ -27,7 +29,14 @@ func (h *ExecAccessHelper) access(
2729
execCommand = v
2830
}
2931

30-
cmd := exec.CommandContext(ctx, "docker", "exec", "-it", containerDetails.Name, execCommand)
32+
commands, err := shlex.Split(execCommand)
33+
if err != nil {
34+
return fmt.Errorf("failed to parse exec command: %w", err)
35+
}
36+
37+
commands = append([]string{"exec", "-it", containerDetails.Name}, commands...)
38+
39+
cmd := exec.CommandContext(ctx, "docker", commands...)
3140

3241
cmd.Stdout = os.Stdout
3342
cmd.Stderr = os.Stderr
@@ -37,7 +46,7 @@ func (h *ExecAccessHelper) access(
3746
return err
3847
}
3948

40-
err := cmd.Wait()
49+
err = cmd.Wait()
4150
if _, ok := err.(*exec.ExitError); ok {
4251
// User may occur ExitError, but it's not needed to handle here.
4352
return nil

0 commit comments

Comments
 (0)