我正在尝试使用单声道进行外部系统调用。我想知道是否可以模拟下面的示例(当然我正在寻找跨平台支持)。
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 命名空间,此代码块就可以工作。