{"record":{"id":"44c20766b6606185","repo":"hashicorp/packer","slug":"error-processing-command-s-44c207","errorCode":null,"errorMessage":"Error processing command: %s","messagePattern":"Error processing command: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/windows-shell/provisioner.go","lineNumber":201,"sourceCode":"\n\t\tlog.Printf(\"Opening %s for reading\", path)\n\t\tf, err := os.Open(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error opening shell script: %s\", err)\n\t\t}\n\t\tdefer f.Close()\n\n\t\t// Create environment variables to set before executing the command\n\t\tflattenedVars := p.createFlattenedEnvVars()\n\n\t\t// Compile the command\n\t\tp.config.ctx.Data = &ExecuteCommandTemplate{\n\t\t\tVars: flattenedVars,\n\t\t\tPath: p.config.RemotePath,\n\t\t}\n\t\tcommand, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error processing command: %s\", err)\n\t\t}\n\n\t\t// Upload the file and run the command. Do this in the context of\n\t\t// a single retryable function so that we don't end up with\n\t\t// the case that the upload succeeded, a restart is initiated,\n\t\t// and then the command is executed but the file doesn't exist\n\t\t// any longer.\n\t\tvar cmd *packersdk.RemoteCmd\n\t\terr = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n\t\t\tif _, err := f.Seek(0, 0); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tif err := comm.Upload(p.config.RemotePath, f, nil); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Error uploading script: %s\", err)\n\t\t\t}\n\n\t\t\tcmd = &packersdk.RemoteCmd{Command: command}","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/windows-shell/provisioner.go#L183-L219","documentation":"Raised in Provision when rendering the provisioner's execute_command template fails. The command string is run through HCL2/Go template interpolation with ExecuteCommandTemplate data (Vars, Path); if the template contains bad syntax or references unknown keys/variables, interpolate.Render returns an error wrapped as \"Error processing command: %s\". This is a template-authoring error, not a guest-side failure.","triggerScenarios":"p.config.ctx.Data is set to {Vars, Path} and interpolate.Render(p.config.ExecuteCommand, ...) errors — malformed {{ }} syntax, unknown function, or referencing a variable not exposed on ExecuteCommandTemplate. provisioner.go:199-204. Common with a customized execute_command containing typos like {{ .Var }} instead of {{ .Vars }}.","commonSituations":"Copy-pasted execute_command from another provisioner (shell vs windows-shell use different fields); stray {{ or }} in a batch command; use of user/template variables without quoting correctly; upgraded templates referencing removed template fields.","solutions":["Fix the execute_command template: valid fields are only {{ .Path }} and {{ .Vars }} (see ExecuteCommandTemplate); correct typos like {{ .Var }} or {{ .Varriables }}.","Balance all {{ }} braces and escape literal braces if the shell command needs them.","Run `packer validate` / inspect the template interpolation of your variables feeding into execute_command.","Fall back to the default execute_command for windows-shell to confirm the rest of the provisioner works, then re-add customizations incrementally."],"exampleFix":"// before: unknown field\nexecute_command = [\"cmd\", \"/c\", \"{{ .Var }} & {{ .Path }}\"]\n// after\nexecute_command = [\"cmd\", \"/c\", \"{{ .Vars }} & {{ .Path }}\"]","handlingStrategy":"validation","validationCode":"// check only supported fields are referenced\nallowed := []string{\".Path\", \".Vars\"}\nfor _, tok := range regexp.MustCompile(`\\{\\{\\s*\\.[A-Za-z]+`).FindAllString(cmd, -1) {\n    if !slices.Contains(allowed, strings.TrimSpace(strings.TrimPrefix(tok, \"{{\"))) {\n        return fmt.Errorf(\"unsupported template field %q in execute_command\", tok)\n    }\n}","typeGuard":null,"tryCatchPattern":"rendered, err := interpolate.Render(cfg.ExecuteCommand, ctx)\nif err != nil {\n    return fmt.Errorf(\"execute_command template invalid (%v); allowed fields: .Path, .Vars\", err)\n}","preventionTips":["Only use {{ .Path }} and {{ .Vars }} in windows-shell execute_command.","Copy execute_command examples from the windows-shell docs, not other provisioners.","Run packer validate to exercise interpolation early.","Incrementally add customizations to the default execute_command."],"tags":["provisioner","windows","template","interpolation"],"backgroundTag":"template-render-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}