Waiting for the command to complete in C# -


text>>

I'm new to C # and trying to develop a small application that internally opens a command prompt And here executes some commands. I have done so far:

  m_command = new process (); M_command.StartInfo.FileName = @ "cmd.exe"; M_command.StartInfo.UseShellExecute = false; M_command.StartInfo.WindowStyle = Process WindowStyle.Hidden; M_command.StartInfo.CreateNoWindow = True; M_command.StartInfo.RedirectStandardInput = True; M_command.StartInfo.RedirectStandardOutput = True; M_command.Start (); M_reader = m_command.StandardOutput; M_writer = m_command.StandardInput; M_writer.WriteLine ("Somecommand"); // Execute some commands  

As you can see, I've redirected the input and output. My question is how do I synchronize "some command", that is, I want to read the result of my instruction through the redirect output. For this, give me the complete order till I have used the command to complete the WriteLine. How can I do this?

It really depends what the command will do. You can wait for the process to exit with Process.WaitForExit , while simultaneously reading from m_reader and OutputDataReceived in another code for. This will only work when the process is over when the command is completed. (Note that you is to read the output, else it can fill the output buffer and basically block the process.)

The second option is to Do you have a certain command when the command is finished - like the next command prompt problem is that if your order outputs the same thing, you will find it wrong.

It seems that launching a command prompt such that it is not a good way. For any reason do not you make a separate process every time?

Another option: If you can work then what is the process of launching through command line through the form of process Wait for the exit of that Although it is difficult - I will actually try to redesign your solution.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -