首页 > 解决方案 > 如何让 c# 进程保持活动状态(节点服务器)

问题描述

您好,我正在 c# 中创建一个打开 node.js 的进程,到目前为止一切都很好,但是当我从我的 cmd 执行相同的命令时,该进程似乎结束了,并且通常它保持活动状态,我怎样才能从 c# 实现这样的事情?这是进程的代码

     private void buttonStartLLodiAgent_Click(object sender, EventArgs e)
    {

        //proc.WaitForExit();
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.CreateNoWindow = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = true;
        psi.UseShellExecute = false;
        psi.RedirectStandardError = true;
        psi.FileName = "node.exe";
        psi.Arguments = AppDomain.CurrentDomain.BaseDirectory + "/LLodiAgent/main.js";
        using (var process = Process.Start(psi))
        {
            //labelStatusLLodiAgent.Text = "Active";
            process.BeginOutputReadLine();
            process.OutputDataReceived += proc_OutputDataReceived;
            //process.WaitForExit();
        }

    }
    public void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        outputConsole.Text = outputConsole.Text + "\r\n" + e.Data;
    }

我的输出正确,但似乎节点服务没有启动,所以我猜它执行但随后杀死它。如何保持服务器活动和 C# 接收数据?

在此先感谢,(这是我的第一篇文章)

标签: c#serverprocess

解决方案


推荐阅读