You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
The text was updated successfully, but these errors were encountered:
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?
The text was updated successfully, but these errors were encountered: