C# 从cmd应用程序接收状态更新
我正在使用一些显微镜软件,它可以通过一个基于命令行的小应用程序进行远程控制。为了更有效地使用这个应用程序,我想用C编写我自己的软件 我已经通过以下方式连接到主软件:C# 从cmd应用程序接收状态更新,c#,events,process,cmd,C#,Events,Process,Cmd,我正在使用一些显微镜软件,它可以通过一个基于命令行的小应用程序进行远程控制。为了更有效地使用这个应用程序,我想用C编写我自己的软件 我已经通过以下方式连接到主软件: public partial class Form1 : Form { Process receiver = new Process { StartInfo = new ProcessStartInfo { FileName = "WSxMrc.exe",
public partial class Form1 : Form
{
Process receiver = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "WSxMrc.exe",
Arguments = "-m recv -a 127.0.0.1 -p 9602",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
private void button1_Click(object sender, EventArgs e)
{
bConnect.Enabled = false;
bDconnect.Enabled = true;
receiver.Start();
}...
使用cmd中的应用程序,它现在可以在获取图像时接收信息,依此类推。我想使用这些收到的状态对发生的任何事情采取行动。例如,在捕获图像后更改扫描区域
我很确定我必须引发某种事件来记录传入状态,这就是我现在的困境所在。我不知道如何创建一个事件来识别何时向接收方进程发送新消息。您需要使用OutputDataReceived事件来处理重定向的输出 在Receiver之后添加这些行。开始
receiver.OutputDataReceived += receiver_OutputDataReceived;
receiver.BeginOutputReadLine();
然后添加事件处理程序
void reciever_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
...
}
更多信息可以在这里找到
非常感谢你的回答。似乎就是我要找的。不幸的是,到目前为止,它还没有发挥作用。我们还查看了msdn链接。我将继续修补它。