Shell Executor (Windows)
Run commands and scripts on Windows using PowerShell, pwsh, or cmd.exe.
Configure the Shell
- DAG defaults (literal values):yaml
shell: powershell -NoProfile steps: - command: Write-Host "Runs with PowerShell" - Step override (evaluated at runtime so params/secrets/outputs are allowed):yaml
steps: - shell: ${SHELL_OVERRIDE:-pwsh -NoProfile} command: Write-Host "Runs in the step shell" - Fallback: If no shell is set, Dagu prefers PowerShell, then
pwsh, thencmd.exe. - String or array:
shellaccepts either"powershell -NoProfile"or["powershell", "-NoProfile"]; arrays avoid quoting issues.
Running Commands
- Inline command string:yaml
steps: - command: Write-Host "Hello from PowerShell" - shell: cmd command: echo Hello from cmd - shell: cmd command: | @echo off echo Multi-line command block echo Runs as a script (not split into args) - Command + args array:yaml
steps: - shell: cmd command: [cmd, /c, echo, Hello from cmd array] - Script block:yamlScripts are saved as
steps: - shell: powershell script: | Write-Host "Multi-line script" Get-Date.ps1files and executed with the selected shell. - Interpreter + inline script:yaml
steps: - command: powershell script: | Write-Host "Inline ps1 body" - Working directory and env: Use
workingDir/dirandenvon the step (or DAG defaults) to control context.
Script Behavior (Windows)
- A
script:block is saved to a temp file in the working directory when possible and removed after the step finishes. - With PowerShell/pwsh, the script is stored as
.ps1and executed by the selected shell. Dagu prefixes each script with$ErrorActionPreference = 'Stop'and$PSNativeCommandUseErrorActionPreference = $trueso cmdlet errors and native command failures stop execution. Withcmd, scripts follow cmd semantics; use PowerShell for richer scripting. - When both
commandandscriptare set,commandis treated as the interpreter and receives the script path directly (no shell wrapper) — useful forcommand: powershellwith inline code.
Shell Options
PowerShell / pwsh
Useshell: powershellorshell: pwsh. Script blocks become.ps1files and are prefixed with$ErrorActionPreference = 'Stop'plus$PSNativeCommandUseErrorActionPreference = $truefor fail-fast behavior on cmdlet errors and native command exit codes (PowerShell 7.4+). Use PowerShell syntax for variables/pipelines.cmd.exe
Setshell: cmdfor command prompt semantics. Include/cin the shell string/array when you want to run a single command string. For multi-line cmd scripts, embed the batch pattern directly in YAML:yamlsteps: - shell: cmd command: | @echo off rem Command || (What to do if it fails) copy file.txt destination_folder\ || exit /b 1 echo This line runs only if the copy succeeded.Direct execution (no shell parsing)
shell: directbypasses shell parsing; use array form:yamlsteps: - shell: direct command: ["C:\\Program Files\\Git\\bin\\bash.exe", -c, "echo from bash in direct mode"]
Tips
- Prefer array syntax for commands with flags to avoid quoting surprises.
- Choose PowerShell for richer scripting; use
cmdonly when you need cmd.exe semantics. - Keep DAG-level shells stable; override per-step only when a different interpreter is required.
- For
.ps1/.cmd/.batscripts in the working directory, use explicit relative or absolute paths to avoid PATH lookup issues.
