How to execute a .bat file from psake?

I am trying to use a scake script in powershell psake to execute a .bat file. Is it possible? Or do I need to make a workaround?

+3
source share
3 answers

Try the following:

task CallBatch {
  exec {cmd.exe /c "path\to\my\testscript.bat"}
}

There is no need to wrap the cmd.exe call in the PSake exec {} function, but if you do this, the assembly will fail if the package returns nothing but 0.

The task below always allows assembly failure:

task Return1FromCmd {
  exec {cmd.exe /c "@exit 1"}
}
+3
source

To execute .bat (or .cmd) from PowerShell:

foo.bat:

@echo off
echo "foo"

foo.ps1:

. .\foo.bat
#or
.\foo.bat
#or
& .\foo.bat

we can run the script:

D:\dev> .\foo.ps1
"foo"
+1
source

:

properties {
  $mybat = 'C:\path\tool.bat'
}

task Test -depends ... { 
  "Bla bla"

  Exec { & $mybat }
}

cmd.exe - & Exec script .

+1

All Articles