After finally getting completely fed up with the standard windows command prompt, I've taken it upon myself to start trying to build a quick and simple alternative to one - an alternative that keeps all of the functions intact (so I shouldn't be rewriting any of them), while just giving it a reasonable interface. It seems to me that the easiest way to do that is by making use of what's already there, with direct calls to existing command line tools. Retrieve the output that a command prompt window would see, show it within the new, not-quite-so-woefully-inadequate interface, done.
So far, I've been able to get a hint of this working with the following code:
This *works*, but brought up a couple of problems:
First of all, this is great if I'm just going to be making calls to executables, which is probably what'll be happening most of the time, but doesn't work for commands that don't run directly off of executables - like dir, md, and other similar commands.
Now, I'm sure that someone is going to suggest that I just write my own variants of these commands in C#, making use of the file I/O functions built into the system libraries of C#. But do consider that recreating these functions in their entirety is just a *little bit* more complicated than finding out how to make calls to the existing commands.
I did try making a call to cmd.exe with arguements /c dir, but each attempt at passing these commands through like that has caused the app to crash.
So, is there any direct way to make calls to those commands in C#? I've also tried using batch files to get around this problem, but I get "file cannot be found" errors whenever I try tio load a .bat file.
Problem number two comes down to how the results are returned, and is probably a major deciding factor on how feasible this whole program really is. Let's say I'm pinging google.com through this app: regardless of whether or not I have that "p.WaitForExit();" line in there, my text box won't be getting updated until the entire ping process has completed. Of course, ideally I'd be getting updates in my textbox after each individual ping result. Take another example: Let's say I'm doing some long (2-hour+) batch renderings with mental ray or some other renderer. Obviously, I'm going to want to periodically see the output statements that the renderer prints to the shell to give me an idea of how far along in the rendering I am. But in the app's current stage, I'd have to wait for the entire rendering to finish before I could see anything about its progress.
So, I really just need a way to retrieve output from the file being run whenever that file gives output, not just when it is finished running. Is this possible?
Thanks!
So far, I've been able to get a hint of this working with the following code:
Code:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.Arguments="/some arguements";
p.StartInfo.FileName = "someexecutable.exe";
p.StartInfo.CreateNoWindow=true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
richTextBox1.Text = output;
This *works*, but brought up a couple of problems:
First of all, this is great if I'm just going to be making calls to executables, which is probably what'll be happening most of the time, but doesn't work for commands that don't run directly off of executables - like dir, md, and other similar commands.
Now, I'm sure that someone is going to suggest that I just write my own variants of these commands in C#, making use of the file I/O functions built into the system libraries of C#. But do consider that recreating these functions in their entirety is just a *little bit* more complicated than finding out how to make calls to the existing commands.
I did try making a call to cmd.exe with arguements /c dir, but each attempt at passing these commands through like that has caused the app to crash.
So, is there any direct way to make calls to those commands in C#? I've also tried using batch files to get around this problem, but I get "file cannot be found" errors whenever I try tio load a .bat file.
Problem number two comes down to how the results are returned, and is probably a major deciding factor on how feasible this whole program really is. Let's say I'm pinging google.com through this app: regardless of whether or not I have that "p.WaitForExit();" line in there, my text box won't be getting updated until the entire ping process has completed. Of course, ideally I'd be getting updates in my textbox after each individual ping result. Take another example: Let's say I'm doing some long (2-hour+) batch renderings with mental ray or some other renderer. Obviously, I'm going to want to periodically see the output statements that the renderer prints to the shell to give me an idea of how far along in the rendering I am. But in the app's current stage, I'd have to wait for the entire rendering to finish before I could see anything about its progress.
So, I really just need a way to retrieve output from the file being run whenever that file gives output, not just when it is finished running. Is this possible?
Thanks!