hashicorp / hashicorp/packer-plugin-sdk
Why not execute the shell command described by the RemoteCmd but the Communicator?
- Dominant language
- Go
- Stars
- 42
- Forks
- 62
- Avg merge
- 29m
- Merged PRs (30d)
- 2
Description
There is one ExecuteCommand field in Communicator struct and trigger the ExecuteCommand execution in the Start() method; But what confused me is that why the command to be executed is not the command described by the RemoteCmd?
```
// https://github.com/hashicorp/packer-plugin-sdk/blob/main/shell-local/communicator.go
type Communicator struct {
ExecuteCommand []string
}
func (c *Communicator) Start(ctx context.Context, cmd *packersdk.RemoteCmd) error {
if len(c.ExecuteCommand) == 0 {
return fmt.Errorf("Error launching command via shell-local communicator: No ExecuteCommand provided")
}
// Build the local command to execute
log.Printf("[INFO] (shell-local communicator): Executing local shell command %s", c.ExecuteCommand)
localCmd := exec.CommandContext(ctx, c.ExecuteCommand[0], c.ExecuteCommand[1:]...)
localCmd.Stdin = cmd.Stdin
localCmd.Stdout = cmd.Stdout
localCmd.Stderr = cmd.Stderr
// Start it. If it doesn't work, then error right away.
if err := localCmd.Start(); err != nil {
return err
}
// We've started successfully. Start a goroutine to wait for
// it to complete and track exit status.
go func() {
var exitStatus int
err := localCmd.Wait()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
exitStatus = 1
// There is no process-independent way to get the REAL
// exit status so we just try to go deeper.
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
exitStatus = status.ExitStatus()
}
}
}
cmd.SetExited(exitStatus)
}()
return nil
}
```
Contributor guide
Assessment
This issue has not been assessed yet.