加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 17:15:51 所属栏目:百科 来源:网络整理
导读:我正在尝试使用mono进行外部系统调用.我想知道是否可以模仿下面的示例(当然我正在寻找跨平台支持). public static int ExecuteExternalApp() { int ExitCode = -1; Process Process = new Process(); ; //Defining the filename of the app Process.StartInf
我正在尝试使用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中有效.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读