2

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

1
  • I don't understand whether you're asking for a class that can wrap I/O redirection like most shells do (as your code demonstrates) or for code that does what the common Unix programs do (as your question says). Don't expect anything does does both, unless it's extremely specialized. Commented Jan 31, 2009 at 20:28

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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?

2 Comments

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.
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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.