Embedd Console in C# with System.Windows.Forms

G

Guest

Hi everybod

who knows the *.dll to embedd the command prompt into C#, what i want to do, is make a graphical command prompt based on System.Windows.Forms

Thanks for helping
 
W

William Stacey [MVP]

TMK, not sure you can that. You can, however, simulate one with a Textbox
or richtext box and doing an input loop.

--
William Stacey, MVP

mh said:
Hi everybody

who knows the *.dll to embedd the command prompt into C#, what i want to
do, is make a graphical command prompt based on System.Windows.Forms;
 
M

Morten Wennevik

Hi,

Can you achieve this by changing input and output (SetIn/SetOut) of the
Console class?

Happy coding!
Morten Wennevik [C# MVP]
 
G

Guest

the problem isn't the graphical programming, i need a dll or something where i can geht the streams of the command prompt....
 
W

Willy Denoyette [MVP]

There is no such DLL, you have to redirect stdin/stdout from the command
shell started by calling System.Diagnostics.Process.Start, to your own
Winforms application.

Willy.
 
B

Ben Abernathy

Hi.

There is a better way to go about doing this. I've done this by creating a
new process and redirecting the standard input, output and error using
stream readers and writers. Then throw in a text box and write some handling
code to use the textbox for the prompt's i/o.

I think I found an exmaple of this on codeproject.com or something like that
and I got something similar to the code below from someone on there so I
don't take credit for this:
//----snip----------
private void handler() {
Process myProcess = new Process();
string output;

myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.Start();
StreamWriter incoming = myProcess.StandardInput;
incoming.AutoFlush = true;
StreamReader outgoing = myProcess.StandardOutput;
StreamReader error = myProcess.StandardError;

incoming.Write("dir c:\\windows\\system32\\*.com" +
System.Environment.NewLine);
incoming.Write("exit" + System.Environment.NewLine);

output = outgoing.ReadToEnd();

if( !myProcess.HasExited )
myProcess.Kill();

textBox1.Text = output;

incoming.Close();
outgoing.Close();
error.Close();
myProcess.Close();

textBox1.Select(0,0);
}
//----snip----------

When done properly, this will yield something like:
http://jinx.psyjnir.net/images/cnsl.png

Note that this code will not allow for real time interraction with the
prompt. It is up to you to find an elegant way to implement that. Anyway, I
hope this helps you out some.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top