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.

Sunday, June 06, 2010

"Exception: Unknown project extension: Library" error when running fdbuild (flashDevelop) from the command line

This happens to me each time I install a fresh copy of flashDevelop.

Each time It takes me some time to figure out why this happens.

next time I will have my blog to remind it happens because:
Because the location of the FLEX SDK is not set in the flash develop setting dialog.

Thursday, May 27, 2010

Hell is other people's CSS rules

A significant part of the JavaScript code I wrote in the last few years is intended to run as part of HTML pages developed by other people.

Now consider the following:

Lets say your JavaScript has a function called "AddButton" that takes a background color, a text color, some text for the button itself and a callback function to call when the button is pressed. and it renders the HTML and CSS that will show this button on the client's page. (Of course in real life this is much more complicated bu this should do to make the point).

You create perfect code, test it on FF,Chrome,IE,Safari,iPhone,iPad and what not, and it looks perfect and works great.

Now your customers/clients start to use your wonderful code and it turns out that one of them has a CSS rule that says "DIV {left-margin:5px}" which causes the texts on your perfect button not to be centered on his site.

So you go and change you code to rended style tags on all your divs saying that their left-margin (and right and top and bottom) are 0px, so your good now.

But then it turns out that another client has "Div {border:1px solid white}" ....
and so on (and of course this is not limited to divs...

How "defensive" should you be "against" the CSS ruls of the hosting page? and what can you do assuming that you don't want to start adding all the possible CSS attributes to every tag you render ?

How would you go about handling this?

Oh... and IFRAMEs are not a valid solution. Well, actually some times they are but lets assume this is not one of those times - why ?

1) Performance
2) Your generated html is required "flow" as part of the hosing page.

Any JavaScript / HTML /CSS lover out there would care to share his thoughts on this ?

Eyal

Sunday, January 03, 2010

Using PSCX from multiple users on same machine

I was having a problem with an automation script I was working on,
It used PowerShell and PowerShell community extensions (PSCX) and it worked fine of for me, but when other people used the same machine - it did not work.

after some looking around - the problem was that PSCX was installed from my user so it was automatically loaded on from my profile.

The resolution:

$pscxInstalled = $false;
$pscxLoaded = $false;
$registeredPSSnapins = Get-PSSnapin -registered
foreach ($registeredPSSnapin in $registeredPSSnapins) {
if ($registeredPSSnapin.Name -eq 'Pscx') {
write-host "PowerShell Community Extensions Found on system" -ForegroundColor green -BackgroundColor black
$pscxInstalled=$true;
$loadedPSSnapins = Get-PSSnapin
foreach ($loadedPSSnapin in $loadedPSSnapins) {
if ($loadedPSSnapin.Name -eq 'Pscx') {
$pscxLoaded=$true
write-host "PowerShell Community Extensions are loaded" -ForegroundColor green -BackgroundColor black
}
}
if (-not $pscxLoaded) {
write-host "Loading PowerShell Community Extensions from registered PSSnapin" -ForegroundColor green -BackgroundColor black
Add-PSSnapin Pscx

}
}
}

Sunday, December 06, 2009

single and double quotes in PowerShell (PoSh)

I was dealing with converting a batch to PoSh and had to create some wired mixture of double and single quotes. I was searching the net and got to this page http://www.vistax64.com/powershell/23546-mix-single-double-quotes.html where he used the following notation:

# $XY$X

so it hit me:
instead of odd things like
write-host '$X'"Y"'$X'

I can do:

$DQ = '"'
$SQ = "'"

and then
write-host '$X$SQ$DQY$DQ$SQ$X'

I guess there might clearer strings to read but at least it works.

maybe
$_DQ_ = '"'
$_SQ_ = "'"

write-host '$X$_SQ_$_DQ_Y$_DQ_$_SQ_$X'

 
Clicky Web Analytics