Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?


C#
<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);
    }


}


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");
Posted
Updated 14-May-19 21:26pm
v3

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[^]
 
Share this answer
 
Comments
Member 14367686 20-May-19 5:36am    
I changed console.write to UI on textview. But it still not solved
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.
 
Share this answer
 
Comments
Member 14367686 15-May-19 3:31am    
writting is on only my python program and reading is only in my C# program now.
how can i synchronise both program?
it seems read all per 60seconds

i haven`t seen this problem from other one by google searching.
my data is just a few. but why this problem was occured from only my project
Richard MacCutchan 15-May-19 4:17am    
As I already explained you are running two independent processes with no synchronisation between them. This means that Windows will decide which one gets activated at any given moment, so there is no way to synchronise the data between them.
Member 14367686 15-May-19 4:52am    
when i test with a lot of data, the event was occured frequently.
it seems ReadLine is occured when buff is full and it can`t find EndofLine.
is here anyone have problem like this?
Richard MacCutchan 15-May-19 4:57am    
There is no solution. If you want the two processes to be synchronised then you cannot run them in this way. They need to communicate with each other so that the writer tells the reader when more data is available. You could try sockets or possibly pipes, but you cannot expect the system to know what you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900