Monday, June 07, 2010

Solution to: Powershell never exists when executed from a batch file / fdbuild

The short story: use <NUL

More details:

I have been using Powershell as part of a build script for a
FlashDevelop project.

The problem was that the Powershell process did not terminate
and so fdbuild.exe did not continue to run.

I searched the web quite a lot until I found the following
two:


They deals with a similar problem that happens when executing
Powershell from WScript.

The explanation given that was that Powershell is waiting for
its STDIN stream to close before it exists and a workaround is
suggested there that fits WScript.

This got me to the following solution for running Powershell
from Flashdevelop/fdbuild/batch:

since IMHO Powershell in those cases does not need any input
from STDIN I assigned NUL as its input stream.

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-Noninteractive -Command "& {$postbuild = (get-item ((get-item
%1).parent.parent.Fullname + '/postbuild.ps1')); & $postbuild
-outputDir %1 -outputName %2; exit $lastexitcode}" <NUL

I use this in a batch file that is called from the post-build
event using the following command line


$(ProjectDir)\..\postbuild.bat $(OutputDir)
$(OutputName)


I guess I could call Powershell directly from the post-build
command line but this will have to wait.

As far as I know I am the first to suggest this workaround,
please add a link to this post if youare quoting it. Thanks.

No comments:

 
Clicky Web Analytics