Is it possible to write to the windows dos screen and display the results in a GUI?

eg;

Console.WriteLine("ipconfig");

            Thread.Sleep(1000);

            for (int i = 0; i < 5; i++)
            {
                textBox1.Text = Console.ReadLine().ToString();     
            }

The method I will use to acheive this is, by making a batch file.
You can create a batch file from your program, the only difference is it ends with a ".bat", rest it is just a text file which contains the commands you want to enter in DOS. And in order to solve the GUI problem what I can think of is writing the output to a textfile and then reading the string into the textbox of the GUI. Hope this helps.

Another way to do this is start a new windows application, then go into the properties and switch it to a command line application. This gives you both a window and a command box.

I found a way of doing this by writing a batch file and executing it within the GUI by using the code;

proc.StartInfo.FileName = "@FILENAME"

I then saved the result by using;

> output.txt"

at the end of my command in the batch file and then I could view the results within the GUI by reading the txt file that was created.

Honestly your solution is totally backwoods.

If you create a new process you can redirect its standard output to a stream, then do whatever you want with it. ex.

CurrentProcess = new Process();
CurrentProcess.StartInfo.FileName = exepath;
				
CurrentProcess.StartInfo.UseShellExecute = false;
CurrentProcess.StartInfo.CreateNoWindow = true;
CurrentProcess.StartInfo.RedirectStandardOutput = true;
CurrentProcess.StartInfo.RedirectStandardInput = true;
CurrentProcess.StartInfo.RedirectStandardError = true;

CurrentProcess.StandardOutput; will return a stream reader object that you can use to do anything you want with the output, for example write it to a text box.

You don't have to resort to a temp file.

Attached is an example of GUI based console, its just as completely basic as it could be, I encourage you to use this method over using the disk.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.