Right now, I'm automating an optimized build process for PHP on Windows that requires a substantial amount of scripting to create the results that I'm looking for. I wrote the first master script in CMD's batch script, which gave me almost satisfactory results. Almost.

Finding myself with the need to recreate the build script, I first had to choose which language to do it in. There are really only two criteria I use when selecting a computer language for a particular task:

1. Does the language have the features/syntax to do the task as simply as possible?

2. What's the bootstrap? (ie, what the heck does it take to get the program up and running where it's going.)

Now, on one hand, I've been tweakin' around building my own scripting language for about a year and a half now (g#), and when I'm working on something that only I will use, I'll often use that. g# is a classless c# dialect that I added powershell to and tacked on a slew of extension methods and scripting hacks that make it kindof sweet. I'm not ready to release it to the world yet (I've decided upon a better architecture, and I'm going to re-write it) , so I don't use it on things that I need to give to others"”which makes it fail #2.

Ok, so I compile a short list of potential candidates, and weigh their potential:

.CMD/Batch:

Aside from the fact that it's already failed me, and I've tried to make it "˜smarter', in the end, there are some things that just end up getting to be too damn messy to implement. Oh, and it sucks.

BASH

Now, that would have been a great idea. Except that BASH isn't native to Windows, and Cygwin isn't"¦ isn't"¦ ugh, don't even bother.

Perl, Python

In my book, they can pass muster on #1"¦ but #2"¦ ooh. no thanks.

PowerShell

I'm *still* not a fan of PowerShell. Even assuming that it might already be on the target box, which takes care of #2, out of all the languages I've encountered, it's the least pleasing to me.

C#

Scripting with C#? "¦ well, it's not really meant to do that. I'd like to just "˜run' the script y'know? I did do a proof of concept a year or so ago, where I wrapped the c# in some JScript, that would automatically call the compiler, and pass arguments thru to the generated EXE:

//@cc_on //@if (@_jscript_version < 5)
#if false
//@end //@if (@_jscript_version < 6)
var args="";
var exename = WScript.ScriptFullName.replace( /\.js$/gi , ".exe" );

var et=" /t:exe"; if( WScript.FullName.toUpperCase().indexOf("WSCRIPT.EXE" ) != -1 ) et=" /t:winexe";
for( each =0; each< WScript.Arguments.length; each++)
args= args+" "+WScript.Arguments(each);
var compilers = new Object(); compilers['.js.js'] = 'jsc.exe'; compilers['.cs.js'] = 'csc.exe'; compilers['.vb.js'] ='vbc.exe';
var WSHShell = WScript.CreateObject("WScript.Shell") ;
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var compiler = compilers[WScript.ScriptName.substr( WScript.ScriptName.length - 6).toLowerCase()];
if( ""+compiler == "undefined" )
WScript.quit(WSHShell.popup("Unable to determine compiler type from filename"));
try {
compiler = WSHShell.RegRead("HKLM\\Software\\Microsoft\\.NETFramework\\InstallRoot") + "v2.0.50727\\"+ compiler;
if( !fso.FileExists( compiler ) )
throw new Error(".NET 2.0 not found");
if( fso.FileExists( exename ) )
fso.DeleteFile( exename );
} catch( e ) {WScript.quit(WSHShell.popup("You do not appear to have .NET 2.0 installed.\n\nYou must install .NET 2.0."));}
var Pipe = WSHShell.Exec(compiler+et+" /nologo /out:\""+exename+"\" \""+WScript.ScriptFullName+"\"" );
while(!Pipe.StdOut.AtEndOfStream)
WScript.StdOut.WriteLine(Pipe.StdOut.ReadLine());
if( fso.FileExists( exename) )
var Pipe =WSHShell.Exec(exename);
while(!Pipe.StdOut.AtEndOfStream)
WScript.StdOut.WriteLine(Pipe.StdOut.ReadLine());
WScript.quit(0);
//@else //@if (@_jscript_version < 5)
#endif
//@end
using System.Windows.Forms;

public class MyMain
{
public static void Main( string[] args)
{
if( args.Length > 1 )
MessageBox.Show("Hello world to you "+args[1]);
else
MessageBox.Show("Hello world!");
}
}
//@end

but, really that's just a tad weird. Plus, it's just not convenient to do batch scripting in.
VBScript

VBScript is a popular choice, it's installed pretty much on all Windows boxes these days, but "¦ I dunno.. There are some things that are just a PITA to do, and scripting external apps isn't fun at all.

JScript

JScript is not too popular of choice--which in my opinion, very weird. Since JScript is essentially JavaScript, it offers a pretty damn flexible language that people enjoy, and there is lots of good references for how to do alot of things. Again, it's already installed pretty much on all Windows boxes, and you have full access to COM and WMI, which on Windows can get you a huge amount of functionality.

On the down side, it's not very "batch friendly""”it lacks the simplicity of executing a program, and leveraging the results for other purposes (like real batch scripting languages like BASH , or "¦ PowerShell).

But, maybe with a bit of linguistic legerdemain, I can fix the shortcomings of JScript, and get a pretty cool language, with very little effort. (Which, I did, and I'll post about next!)