在linux上,我有一些关于在monodevelop C#上处理Python的问题 [英] At linux, I have some problem about processing Python on monodevelop C#

查看:119
本文介绍了在linux上,我有一些关于在monodevelop C#上处理Python的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi. i have some problem when i process python on monodevelop C#.
at first , my program is launching on C# ( ubuntu Monodevelop )

and i want to process some python program ( by using bash )

it was done. i`ve succeed to process my python program by using 'Process' class

but when i get result of Program line by line, there was some problem
my python program give result line maybe once per a sec.
but when i try 'ReadLine', it didn`t give me result once per a sec.
it seems 60 line per 60sec. ( Read 60 Lines at once )

i need result everyseconds.
whats wrong on my code or how can i get result every seconds?







<pre>using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
public class monostart:Form
{
    public static void Main()
    {
        Application.Run(new monostart());
    }

    public monostart()
    {
        this.ClientSize = new Size(960, 540);
        BaseBoard(this);
    }
    public void BaseBoard(Form baseboard)
    {
        Button testgButton = new Button();
        testgButton.Click += TestgButton_Click;
        testgButton.Height = 30;
        testgButton.Width = 30;
        testgButton.Location = new Point(300, 300);
        testgButton.Parent = Base;
      


    }

    void TestgButton_Click(object sender, EventArgs e)
    {
        Process proc = new Process();

     
        proc.StartInfo.FileName = "/bin/bash";
        proc.StartInfo.Arguments = "-c \"cd body25_2 && bash run_softmax.sh\"";
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.StartInfo.CreateNoWindow = false;
        proc.OutputDataReceived += new DataReceivedEventHandler(receive);
        proc.Start();

        proc.BeginOutputReadLine();
        proc.WaitForExit();
   
        //   while(!proc.StandardOutput.EndOfStream)
        //   {
        //       string temp = "text : ";
        //       temp += proc.StandardOutput.ReadLine();
        //       Console.WriteLine(temp);
        //   }


    }
    void receive(object e, DataReceivedEventArgs outLines)
    {
        System.Console.WriteLine("Line = " + outLines.Data);
    }


}





我的尝试:



'而'和'Handler'

但都失败了



我的python程序使用'print'函数给出结果。

我尝试了

print(~~~~);

print(~~~ \ n);

print(~~~ \\\\ n);



What I have tried:

'while' and 'Handler'
but all was failed

my python program give result by using 'print' function.
and i tried
print("~~~~");
print("~~~\n");
print("~~~\r\n");

推荐答案

你的bash和console都写入标准输出;得到一个写别的东西(例如std错误)。不确定这些组件有多复杂。



Process.StandardOutput属性(System.Diagnostics)| Microsoft Docs [ ^ ]
Your bash and console are both writing to "standard output"; get one to write to something else (e.g. std error). Not sure how sophisticated these components are.

Process.StandardOutput Property (System.Diagnostics) | Microsoft Docs[^]


如果没有某种同步两个进程的方法,则无法控制每次接收的数据量。目前它们都是独立运行的,因此系统将决定每个人何时可以读取或写入一些数据。
You cannot control how much data will be received each time without some method of synchronising the two processes. As it stands they both run independently and so the system will decide when each one can read or write some data.


这篇关于在linux上,我有一些关于在monodevelop C#上处理Python的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆