Reputation: 14698
I am trying in a powershell psake script to execute a .bat file. Is this possible? Or do I have to do a workaround?
Upvotes: 3
Views: 491
Reputation: 38851
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.
Upvotes: 1
Reputation: 3111
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"}
}
Upvotes: 3
Reputation: 3868
To execute a .bat (or .cmd) from PowerShell:
foo.bat:
@echo off
echo "foo"
foo.ps1:
. .\foo.bat
#or
.\foo.bat
#or
& .\foo.bat
we can then run the script:
D:\dev> .\foo.ps1
"foo"
Upvotes: 1