A First Look At Monad
One of the things that makes UNIX so powerful is that it consists of numerous utlity programs that only do simple things. You use those utilities by linking them using pipes. For example:
zef@zerver:~$ cat unsorted.txt Jake Pete Zef Adia Anna Monica Ross zef@zerver:~$ cat unsorted.txt | sort Adia Anna Jake Monica Pete Ross Zef
All an utility has to do is interpret the input, do something with it and then send the manipulated data as text to the output.
This is where Monad builds on. Monad is the code name of the new Windows Command Shell (WSH). WSH is the replacement of Windows’ standard console (cmd). It adds substantial features that make it a whole lot easier to use and way more powerful than it was.
*Providers*
Let’s start off with the simple stuff, browsing your harddisk. Like with older versions of the console (and MS-DOS before that), there are basic commands like cd and dir. Additionally some more UNIX commands are added, such as ls, cat, pwd and probably more:

What’s different is that there’s now a more generic way of browsing like this. What you can do is create your own so-called providers. Providers implement a certain interface and can allow anything to act like a file-like system. By default you will use the FileSystem provider, but there are many more:

The registry for example:

With the package I received there was also a provider for XML documents but I couldn’t get that to work, sadly.
*Cmdlets*
Cmdlets (command-lets) are little managed programmes (written in a .NET language) that are like a UNIX utility. It does something with its input (if it has any) and produces output. The difference is that it doesn’t produce text, it produces a stream of .NET objects. You can pipe through this stream of objects to other Cmdlets which can then manipulate them. What’s nice about this is that there’s no need for your input and output to be pure text and also you don’t have to do any parsing, it all works automatically. For example, when I want to order the list of currently running processes in a descending fashion by the process names:

No need to parse the output of get-process, it’s just a stream of objects that you can manipulate. A very simple Hello World cmdlet (that takes no input) would look like this:
using System.Management.Automation;
[Cmdlet( "Invoke", "HelloWorld" )]
public class InvokeHelloWorld : Cmdlet {
protected override void ProcessRecord() {
WriteObject("Hello World");
}
}
There are also Cmdlets that convert object streams from and to XML files or even to Word or Excell files.
*Scripting*
WSH also has scripting capabilities. These capabilities integrate very nicely into the .NET framework. Some examples:
MSH>$name = "Zef Hemel"
MSH>$name
Zef Hemel
MSH>$name.ToUpper()
ZEF HEMEL
MSH>$name[0..2]
Z
e
f
MSH> $a = @{one= 1; two= 2; three= 3}
MSH> $a
Key Value
--- -----
one 1
three 3
two 2
But that’s just simple stuff. You can do much more complicated things like conditional statements and loops aswell.
*Extensibility*
The whole system is extensible. You can create your own Cmdlets and your own Providers. Cmdlets can be written using the cmdlet scripting language or any .NET language such as C# or VB.NET.
*More information*
More information can be found in this “Channel9 video”:http://channel9.msdn.com/ShowPost.aspx?PostID=25506 (including information on how to get your beta copy of WSH) and “this .NET Show episode”:http://msdn.microsoft.com/theshow/Episode043/default.asp.
Jacob Duursma said,
Wrote on October 16, 2004 @ 3:57 pm
Interresting stuff. It is funny to see that after many years of increased GUI improvements and increased usage of the GUI all of the sudden windows has an improved command shell.
I expected this to happen many years ago, it seems a bit ‘late’ now. But better late then not at all.
Zef said,
Wrote on October 16, 2004 @ 4:00 pm
Note that this pass-object model is made possible (and doable) mainly because of the deep integration of the .NET framework, which has only existed for around three years.
And the guy in the Channel9 video even talked about that applications should let you do everything through the command line. The GUI should just be a easy to use interface to the CLI. That’s quite a turn-around.
Jacob Duursma said,
Wrote on October 16, 2004 @ 7:01 pm
In UNIX this has been the case for quite some time now. Maybe the pass-object model using .NET is quite new where UNIX commandline tools pass just plain text. Still the same principles apply, you can do everything with the commandline and some things also trough GUI.
I didn’t expect the pass-object model, but I did expect a better shell earlier on. More then just the few improvements that have been made from 95->XP.
Zef said,
Wrote on October 16, 2004 @ 7:15 pm
Well, the shell has improved since 98. Since 2000 it has path completion and you can also scroll through the window. Windows 9x didn’t have that.
Jacob Duursma said,
Wrote on October 16, 2004 @ 9:09 pm
That’s what I classified as ‘few improvements’. Which are more a usability thing then real commandline power.
Andrew said,
Wrote on October 18, 2004 @ 10:53 pm
using System.Management.Automation;
[Cmdlet( “Invoke”, “HelloWorld” )]
public class InvokeHelloWorld : Cmdlet {
protected override void ProcessRecord() {
WriteObject(”Hello World”);
}
}
Well of course! Much better than…
echo “Hello World”
Whatever. Just tell me that there is an command line implementation of ‘man’?