我对以下代码有疑问:
private void Form1_Load(object sender, EventArgs e)
{
cmdOutput = new StringBuilder("");
cmdProcess = new Process();
cmdProcess.StartInfo.WorkingDirectory = @"C:\android-sdk\tools";
cmdProcess.StartInfo.FileName = @"java";
cmdProcess.StartInfo.Arguments = @"-Xmx512m -Djava.ext.dirs=lib\;lib\x86_64 -Dcom.android.monkeyrunner.bindir=..\framework -jar lib\monkeyrunner.jar";
cmdProcess.StartInfo.UseShellExecute = false;
cmdProcess.StartInfo.CreateNoWindow = true;
cmdProcess.StartInfo.RedirectStandardOutput = true;
cmdProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
cmdProcess.StartInfo.RedirectStandardInput = true;
cmdProcess.Start();
cmdStreamWriter = cmdProcess.StandardInput;
cmdProcess.BeginOutputReadLine();
// Even if i fire this later it doesn't work.
cmdStreamWriter.WriteLine(@"print 'Hello World'");
}
问题是:
cmdStreamWriter.WriteLine(@"print 'Hello World'");
是什么都不做。没有任何东西被写入 java 进程。
输出似乎工作正常(通过将脚本直接加载到monkeyrunner.jar进行测试。但尝试多次后我没有得到任何输入。
如果我将进程更改为“cmd”,这确实可以正常工作