我正在尝试使用mono进行外部系统调用.我想知道是否可以模仿下面的示例(当然我正在寻找跨平台支持).
public static int ExecuteExternalApp() { int ExitCode = -1; Process Process = new Process(); ; //Defining the filename of the app Process.StartInfo.FileName = "java"; //Assigning the args to the filename Process.StartInfo.Arguments = @"-jar """ + ConfigurationManager.AppSettings["JarPath"].ToString(); try { //Starting the process Process.Start(); //Waiting for the process to exit Process.WaitForExit(); //Grabbing the exit code ExitCode = Process.ExitCode; //Close the process Process.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } return ExitCode; }
**更新:此代码可以单声道工作.由于对System命名空间的不存在引用(不知道如何发生),第一个实现不起作用,只要使用System.Diagnostics命名空间,此代码块就可以工作.
解决方法
我不确定这是否是您想要的,但请查看我在
Windows Service Application Controller中发布的代码示例,这在Mono中有效.