简体   繁体   English

从c#调用Octave命令的问题

[英]Problem with Invoking Octave commands from c#

I am trying to use surf function of Octave to plot 3d data from my c# application. 我正在尝试使用Octave的冲浪功能来绘制来自我的c#应用程序的3d数据。

I use Process.Start() to start Octave and Process.WriteLine() to send commands The same method works fine to plot using gnuplot but it's not working with Octave 我使用Process.Start()来启动Octave和Process.WriteLine()来发送命令相同的方法可以很好地使用gnuplot进行绘图但是它不适用于Octave

Process octavePro;
        StreamWriter octaveStWr;
        string octavepath = @"C:\Octave\Octave-5.1.0.0\mingw64\bin\octave-cli-5.1.0.exe";
    private void button1_Click(object sender, EventArgs e)
    {
        octavePro = new Process();
        octavePro.StartInfo.FileName = octavepath;
        octavePro.StartInfo.UseShellExecute = false;
        octavePro.StartInfo.RedirectStandardInput = true;
        octavePro.StartInfo.RedirectStandardOutput = true;
        octavePro.StartInfo.RedirectStandardError = true;
        octavePro.StartInfo.CreateNoWindow = false;
        octavePro.OutputDataReceived += new DataReceivedEventHandler(InterProcOutputHandler);
        octavePro.ErrorDataReceived += new DataReceivedEventHandler(InterProcOutputHandler);
            octavePro.Start();
            octaveStWr = octavePro.StandardInput;
            Thread.Sleep(100);
            octaveStWr.WriteLine("info");
            octaveStWr.WriteLine("surf([1 2 3; 2 3 4; 3 4 5])");
            octaveStWr.Flush();
        }

When I execute the two command "info" and "surf([1 2 3; 2 3 4; 3 4 5])" in Octave-CLI, I get application information and 3d plot for the data respectively. 当我在Octave-CLI中执行两个命令“info”和“surf([1 2 3; 2 3 4; 3 4 5])”时,我分别得到数据的应用信息和3d图。 But when I try to execute it from C# application, only a terminal window is started and nothing is displayed in the window. 但是当我尝试从C#应用程序执行它时,只启动一个终端窗口,窗口中没有显示任何内容。

You may need to increase the sleep time for the initialization of Octave. 您可能需要增加Octave初始化的休眠时间。 Depending on the duration of each command you may need add more sleeps. 根据每个命令的持续时间,您可能需要添加更多睡眠。 Also use waitfor to suspend the execution of Octave until the figure is closed. 也可以使用waitfor暂停Octave的执行,直到数字关闭。

octavePro.Start();
octaveStWr = octavePro.StandardInput;
octavePro.BeginOutputReadLine();
octavePro.BeginErrorReadLine(); 
Thread.Sleep(5000);
octaveStWr.WriteLine("info");
Thread.Sleep(1000);
octaveStWr.WriteLine("waitfor(surf([1 2 3; 2 3 4; 3 4 5]))");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM