Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting command line output dynamically
    primarykey
    data
    text
    <p>I'm running a program using command line in c# this program produce some logs while its running in need to display this logs whenever it get change. I wrote the following code but it shows all the logs once the process has been killed and during the running time my program is not responding. how can I fix it?</p> <p>regards</p> <pre><code>ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "C:\\server.py"); Process proc = new Process(); procStartInfo.WindowStyle = ProcessWindowStyle.Hidden; procStartInfo.UseShellExecute = false; procStartInfo.RedirectStandardOutput = true; //procStartInfo.CreateNoWindow = true; proc.StartInfo = procStartInfo; proc.Start(); string output = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(300); LogstextBox.Text = output; </code></pre> <p><strong>Edited:</strong> well, I tried to use <code>OutputDataReceived</code> but it doesn't show any result, here is the changed code:</p> <pre><code>{ //processCaller.FileName = @"ping"; //processCaller.Arguments = "4.2.2.4 -t"; this is working processCaller.FileName = @"cmd.exe"; processCaller.Arguments = "/c c:\\server.py"; //this is not working processCaller.StdErrReceived += new DataReceivedHandler(writeStreamInfo); processCaller.StdOutReceived += new DataReceivedHandler(writeStreamInfo); processCaller.Completed += new EventHandler(processCompletedOrCanceled); processCaller.Cancelled += new EventHandler(processCompletedOrCanceled); this.richTextBox1.Text = "Server Started.." + Environment.NewLine; processCaller.Start(); } private void writeStreamInfo(object sender, DataReceivedEventArgs e) { this.richTextBox1.AppendText(e.Text + Environment.NewLine); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload