如何在android应用程序上使用Xamarin C#启动流程?

如何在android应用程序上使用Xamarin C#启动流程?,c#,shell,xamarin,uwp,process,C#,Shell,Xamarin,Uwp,Process,有此代码: Process checkForUpdates = new Process(); checkForUpdates.StartInfo.FileName = @"python"; checkForUpdates.StartInfo.Arguments = "-V"; checkForUpdates.StartInfo.UseShellExecute = true; checkForUpdates.StartInfo.RedirectStandardOutput =

有此代码:

  Process checkForUpdates = new Process();
  checkForUpdates.StartInfo.FileName = @"python";
  checkForUpdates.StartInfo.Arguments = "-V";
  checkForUpdates.StartInfo.UseShellExecute = true;
  checkForUpdates.StartInfo.RedirectStandardOutput = true;
  checkForUpdates.StartInfo.RedirectStandardError = true;
  checkForUpdates.StartInfo.CreateNoWindow = false;
  checkForUpdates.EnableRaisingEvents = true;
  checkForUpdates.Start();
  string result = checkForUpdates.StandardOutput.ReadToEnd();
我试图检索命令python-V的输出,以确定设备上是否安装了python

上面的代码可以编译,但在编译过程中代码似乎挂起,没有任何错误。同样的代码在UWP上也可以正常工作


有没有其他方法可以让它在Android上工作?

问题是我在后台工作程序中运行了这段代码。我将代码直接放在ViewModel内部的一个方法中,它工作得非常好。

这似乎假设python在路径中。。。如果不是呢?您的代码将挂起,直到在标准输出中检测到EOF为止,而在python脚本终止之前,EOF永远不会发生。当python终止时,标准输出将被释放,因此您不会得到任何数据。我建议使用与ReadToEnd()不同的方法读取StandardOutput。如果它不在路径中,我不应该得到一个错误来说明这一点吗@问题是即使我不读任何东西,脚本也不会终止。我尝试使用checkForUpdates.OutputDataReceived+=(s,er)=>{Debug.WriteLine(er.Data);}使用读取输出;但是结果是一样的,所以我不运行任何python脚本。-V命令仅在安装时返回python版本。流结束和文件结束之间存在差异。当您在Windows中打开文件并到达文件末尾时,Windows将自动关闭文件/流,然后c#应用程序将获得EOF。对于流,除非应用程序关闭流,否则将一无所获。流的位置将位于最后一个位置,但除非您测试该位置,否则不会得到任何指示。Windows假定填充流的过程将添加更多数据。要获得EOF,python脚本需要关闭标准输出。