Making my own command prompt

  • Thread starter Thread starter C. Adam Barney
  • Start date Start date
C

C. Adam Barney

I would like to create my own command prompt application using .NET.
I'm looking to start off with a basic framework, essentially passing
commands through to cmd and displaying the results.

However, I'm stuck on creating even the framework. The approach I've
been looking at involves using a process object and tapping into the
StandardInput and StandardOutput streams, but I can't see how to make
this interactive, like a shell should be.

Is this a much bigger task than I've imagined? (I've imagined that
this should be fairly straight forward and simple.)

Any help or general direction you can provide will be greatly
appreciated.

Thanks!

Adam
 
Adam,

You are on the right track. I think that you just need a kickstart.
Basically you have to set UseShellExecute to false and RedirectStandardOutput
to true. I have posted a sample below that demonstrates what you are asking
about.

I hope this helps.
----------------------

//try NET as Command and VIEW as argument
string myInput, myArgs;
Console.WriteLine("Input Command:");
myInput = Console.ReadLine();
Console.WriteLine("Input Argument(s): ");
myArgs = Console.ReadLine();
ProcessStartInfo pi = new ProcessStartInfo();
pi.FileName = myInput;
pi.Arguments = myArgs;
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
Process p = new Process();
p.StartInfo = pi;
p.Start();
Console.WriteLine(p.StandardOutput.ReadToEnd());
 
Back
Top