views:

703

answers:

3

Is there an implementation of a Unix shell and commands as a .Net assembly. This could be a wrapper around cygwin, or a standalone built from public domain source. The kind of commands I'd really like to be able to use are wc, tar, cpio, ps, kill, cat, at ...

how cool would it be to do this (Pseudo code)

usng cygwin

.....

 Shell myShell = new Shell("cat file1 file2 >> file3");
 myShell.Run(DateTime.Now);

Edit > I can see the shell out approach working, I've used that approach myself in the past. However, it just feels ugly, it's another process running, it's not secure, it requires another install on client machines, you have to muck around build command strings. As a further example

 Shell myShell = new Shell();
 myShell.Infiles.Add (streamObject);
 myShell.Outfiles.Add (streamObject);

 myShell.Stderr.NewOutput += myErrorLogger();

etc

+2  A: 

Have you looked at PowerShell? Many tasks using Unix commands can be translated into PowerShell.

Mitch Wheat
+1  A: 

Probably something like the following will do.

Shell myShell = new Shell("c:\cygwin\bin\bash cat file1 file2 >> file3");  
myShell.Run(DateTime.Now);

But, I don't have an environment to test it.

Give it a try.

OscarRyz
+1  A: 

I don't know of any implementations, but I think what you have is an interesting idea:) Would be a fun project for someone to develop a managed version of busybox that can run in its own console and be consumable by a .NET assembly like in your sample code. But would something like this really be useful to many people?

barneytron
Interesting, this would be a good starting point. As to being useful, my first problem like this, say 10 years back was word counting a big file on a windows box. Even native C code couldn't match the performance of wc, so I hacked a wrapper around MKS toolkit, it was a kludge then and still is.
MrTelly
I'm a big fan of Cygwin; it's the first thing I install to feel at home when handed a new Windows rig at work. Nevertheless, I only use the basic commands, so I might prefer to have one assembly that does that instead. Now I'm tempted to take a peek at the BusyBox code to assess its portability :)
barneytron