微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 从.NET到单声道的系统调用

我正在尝试使用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中有效.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐