Project Description
Use a regular programming language for command line scripting! Scriptster integrates C# with a command line interpreter, allowing you to write batch files in this very powerful, type safe language.

Scriptster is a single executable that is copy-deployable: simply copy it into a directory of your choice, run
    scriptster --install

(from a command prompt started with administrator privileges - "Run as Administrator"), and close and reopen CMD windows where you expect to be using it (CMD needs update to PATHEXT environment variable, which it reads on load).

After this, you can author and run C# scripts. For example, open a notepad, and type the following:
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("This program was invoked with the following command line parameters:");
        foreach(string s in args)
            Console.WriteLine("{0}", s);
    }
}

Save this file as testscript.csscript, and you can run it directly from the command line:
    c:\temp> testscript Blah blah blah
    This program was invoked with the following command line parameters:
    Blah
    blah
    blah


Uninstalling Scriptster is as easy:
    scriptster --uninstall

and then delete the file scriptster.exe.

If you need to reference an assembly, add "//#ref assembly_name.dll" line to a script (it could be anywhere in the file, but must start in the beginning of the line), as follows:
//#ref System.DirectoryServices.dll
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        DirectorySearcher ds = new DirectorySearcher();

        ds.PropertiesToLoad.Add("mail");

        foreach (string alias in args)
        {
            ds.Filter = "(SAMAccountName=" + alias + ")";
            SearchResult result = ds.FindOne();
            if (result == null)
            {
                Console.Error.WriteLine("Could not resolve {0}", alias);
                continue;
            }
            Console.WriteLine("{0}'s email is {1}", alias, result.Properties["mail"][0].ToString());
        }
    }
}


How does this work?

It's actually very simple (the whole program for Scriptster is less than 500 lines of code, and this includes comments!).

Scriptster maintains a cache of compiled code. When you start a script, Scriptster is launched with the script and its command line parameters as arguments. It then checks if this script has already been compiled. If no, or compiled copy is older than the script file, it compiles the executable and puts it in the cache. It then proceeds to start the cached executable.

The visible effect to the user is as if the script were running directly from the command line, just like a .CMD or a .BAT file.

Last edited Jul 1, 2009 at 6:09 AM by SergeySolyanik, version 2