Emulating the Command Prompt in C# (Part 2)

Last post I demonstrated how to make a simple command prompt using a basic Console project. This time I’m going to show how to embed one in a window.

I’ll admit it, getting this to work was not particularly easy. I tried a number of different methods, from redirecting the output stream to parenting the console window. Redirecting the output stream didn’t work because not all of the output could be read until the program finished executing. Parenting the console window didn’t work because it wouldn’t draw correctly when I removed the border. In the end, I had to copy the text from the console buffer itself.

Hooray, more P/Invoke.

Continue reading


Emulating the Command Prompt in C#

The school I go to places ridiculous restrictions on the computers. Right clicks aside, one thing I wish above all things they hadn’t disabled was the command prompt. Ironically, the computers also have support for a number of programming languages. A friend of mine managed to emulate one using Python, and all was swell. The best part was that he coded in functionality to automatically add things to the system path. You see, we were doing quite a bit of C++/MinGW at the time… off our USBs of course.

I decided to make my own. The Python script had the added bonus of being cross platform, but it would be quite the stretch to expect every Windows machine in the world to have Python installed. I wanted my own custom command prompt. Because I rarely use Mac/Linux, .NET is installed on all up-to-date Windows machines, and it’s simply an awesome language, I decided to use C#.

Continue reading