How to execute a .bat file from psake?
Try the following:
task CallBatch { exec {cmd.exe /c "path\to\my\testscript.bat"}}
It is not necessary to wrap the call to cmd.exe in PSake's exec {} function, but if you do it, the build fails if the batch returns anything but 0.
The task below always lets the build fail:
task Return1FromCmd { exec {cmd.exe /c "@exit 1"}}
To execute a .bat (or .cmd) from PowerShell:
foo.bat:
@echo offecho "foo"
foo.ps1:
. .\foo.bat#or.\foo.bat#or& .\foo.bat
we can then run the script:
D:\dev> .\foo.ps1"foo"
This works for me:
properties { $mybat = 'C:\path\tool.bat'}task Test -depends ... { "Bla bla" Exec { & $mybat }}
No need to directly mention cmd.exe
-- using &
in the Exec script block seems to be enough.