Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi,

i am trying to develop form based appl. in that i have homeform by clicking on one menu item it will open another window . in that window the last step is compilation of cpp files and paralelly display status of compilation to user on homeform by closing the current window.

i am collecting set of cpp sourcefiles to a list and using following code multiple times(based on number of files)for compile.

public void ExecuteCommandSync(string command)
        {
           // create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters.
                // Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit.
                System.Diagnostics.ProcessStartInfo procStartInfo = new
                 System.Diagnostics.ProcessStartInfo("cmd", "/c" + command);
                // The following commands are needed to redirect the standard output. 
                procStartInfo.RedirectStandardOutput = true;
                procStartInfo.RedirectStandardError = true;
                procStartInfo.UseShellExecute = false;
               // Now we create a process, assign its ProcessStartInfo and start it
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo = procStartInfo;
                proc.Start();
                // Get the output into a string
                string result = proc.StandardOutput.ReadToEnd();
                string error = proc.StandardError.ReadToEnd();
                                                            
            }


we are trying to write "error" and "result" strings in above code to a list<string> and trying to display on homeform . but when we close current window that list<string> is not redirecting to homepage.and i am unable to achive parallelism (compiling and status display to homepage).

above function will be called for multiple times (based on number of cpp files selected for compilation).
Posted
Comments
Sergey Alexandrovich Kryukov 11-Jan-12 23:58pm    
Please don't re-post. You could have answered your follow-up questions on the page of your previous question.
--SA

1 solution

Not only this is essentially a re-post (please see my comment to the question), but you apparently ignored my past answer redirection of processstatus[^].

Did I explain that you don't need to run "cmd" with "/c"? You don't need it. Even in my previous answer shown above I had to repeat same things more than once. Not you are using two redirected streams, which is good.

Now, what is "is not redirecting to homepage"? what's "homepage"? This term looks completely irrelevant.

You don't need to check the project status. However, you can. All you need is here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].
What you really need is synchronization with the process you've spawned. You need to make a blocking call which would put your thread to sleep until the child process terminates. For this purpose, call System.Diagnostics.Process.WaitForExit(). That's it.

And, of course, always execute it all in a separate thread. See my previous answer references in first paragraph of this one.

—SA
 
Share this answer
 
Comments
pasupulety 12-Jan-12 1:30am    
1) how can run command prompt without using "cmd" with "/c". i dont know exactly what "cmd","/c" is? but still using for command execution.

2) HomeForm or homepage :- In my project in the begining it will display one form with menu items and all. after that i am trying to click on one menu item there i starts the process of "environment creation".

in home form we have menu item file in that file->c and cpp enviroment-> ENTER

this displays another form where we select compiler options and source files to be compiled in step by step process. at the last step of this current window i have build button. clicking on this button starts compiling selected source files based on compiler options selected. so now my problem starts ... this compilation status(successfull compiled files should be displayed on home page in some panel) while compilation is going on. and if any error comes in compilation the build process should abort by displaying error message to user.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900