Hey so I’ve been dealing with this issue for a while. So, part of my program requires me to access Adb (android development bridge) and I do that through cmd prompt and bat files. The problem is my when running my program a blank CMD window comes up when it comes time to execute the bat, and the bat won’t execute until I close the CMD window. ANy ideas why?
Here’s what I tried:
Process compiler = new Process();
compiler.StartInfo.FileName = "push.bat";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.StartInfo.RedirectStandardError = true;
compiler.Start();
string d = compiler.StandardOutput.ReadToEnd();
MessageBox.Show(d);
Blank CMD window. I also tried this
Process compiler = new Process();
compiler.StartInfo.FileName = "cmd.exe";
compiler.StartInfo.Arguments = " /c push.bat";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.StartInfo.RedirectStandardError = true;
compiler.Start();
string d = compiler.StandardOutput.ReadToEnd();
MessageBox.Show(d);
Still empty CMD window with blinking cursor comes up that won’t do anything until I close it.
I think what’s happening is that you are reading until the stream closes, but it doesn’t close until
push.batexits.Try using the OutputDataReceived and ErrorDataReceived events and the
WaitForExit()method.This will let you asynchronously read the data and you will know when it exits when your call passes the
WaitForExit()call.Example: