So, I'm giving a demo of a program that I've written for my boss. The program is loaded with test code that I use to ensure various options an routines are set properly, and show up in a listbox in the application (was going to remove it once the program was completed). One of the aspects of the program is that a command window pops up showing the results of an external application process. The boss would really like for me to remove the CMD window, and have the output of that piped into my listbox.
... If you're using the Process class to start the external app, set ... to true. ... In that class you can also redirect the standard output of the process and put it into a variable. Here's an ... on how
I'm not getting it I guess. I have both articles up (from Tinstaafl and TnTinMN) and I've implemented those processes. I have mixed results from it though. No text is displayed...so I don't know what's going on. At first, I was trying to send the output of that command window to a listbox that I was using for troubleshooting purposes. Needless to say, the listbox did not display the output from the RedirectStandardOutput command.
So to test out the functions, I created a new form and did basic DIR commands using Process and RedirectStandardOutput. I had it going to a Listbox and a Textbox. It worked fine for the Textbox, but not the Listbox. Ok...so I go back to my program, and added a textbox to get the desired output, and I still got no result. Here's the code:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = ScanS;
p.StartInfo.Arguments = allScanOpt;
string output = p.StandardOutput.ReadToEnd();
tbxOutput.Text = (output);
So, to be clear on what's going on, the ScanS variable is the path and excecutable to Microsofts ScanState program. The allScanOpt variable is the series of switches need for the ScanState program to function as desired. All of that is good, but I'm not seeing the ScanState process logged in the textbox. If I couldn't see my HDD light going to town, then I'd swear my program has locked up and nothing was working.
That definitely gets me closer. The typical output of the scanstate.exe application is not showing up in the textbox, however once Scanstate is completed, it does return a status code in the textbox, which will be good enough for now.
I'm now behind schedule on this build, so I'm going to have to move forward on the other functions. I'll come back to this problem later on in the week. Thanks TnTinMN and tinstaafl.