c# - 如何让 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# 接收数据?
在此先感谢,(这是我的第一篇文章)
解决方案
推荐阅读
- ios - 如何在此代码的后台集成相机
- javascript - Typescript + Require.js + PIXI 6 - 导入附加到窗口但在主范围内未定义
- javascript - 为什么我得到三个未定义的东西,为什么一次调用有两个输出?
- javascript - 如何从外部函数访问我的类中的构造函数成员?
- entity-framework-core - 使用 DB Context Factory 的身份存储
- c# - 选择列组合框时如何用数据库内容填充datagridview单元格
- java - 如何从 file.txt 中读取整数(矩阵)并添加到数组中?
- java - 使用总订单关系的优先级队列
- python - 没有键入模块 TypeError 的 Python 类型别名:“类型”对象不可下标
- operating-system - 有正/负的 ready_rate 和 running_rate 有什么作用?