C# Ping -t stopping by button - c#

I have little problem with stopping infinite Pinging.
If you see in picture I ping IP 127.0.0.1 it has infinite ping ( -t ).
And I want do that when I Click Stop! button then it stops pinging.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Net;
using System.Management;
namespace PingProgramm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread th;
private void button1_Click(object sender, EventArgs e)
{
th = new Thread(thread1);
th.Start();
}
public void thread1()
{
try
{
string command = "/c ping -t " + textBox1.Text;
ProcessStartInfo procStartInfo = new ProcessStartInfo("CMD", command);
Process proc = new Process();
proc.StartInfo = procStartInfo;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardInput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
proc.Start();
proc.BeginOutputReadLine();
proc.WaitForExit();
}
catch (Exception)
{
//if an error occurs with in the try block, it will handled here.
}
}
void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
string newLine = e.Data.Trim() + Environment.NewLine;
MethodInvoker append = () => richTextBox1.Text += newLine;
richTextBox1.BeginInvoke(append);
}
}
bool firstTime = true;
private void textBox1_Click(object sender, EventArgs e)
{
if (firstTime)
{
firstTime = false;
textBox1.Clear();
}
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}
Best wishes
KLDesigns,

The simplest thing that might work in your current code is to get hold of your Process instance in the DataReceived event and cancel the process there (or send a Ctrl+C on the stdin).
void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (stop)
{
// sender is our process instance
// so we can cast that safely here
var proc = (Process) sender;
// brutally kill it
proc.Kill();
// or more gently, send a ctrl+C
// http://stackoverflow.com/a/285041/578411
proc.StandardInput.Close();
}
if (e.Data != null)
{
string newLine = e.Data.Trim() + Environment.NewLine;
MethodInvoker append = () => richTextBox1.Text += newLine;
richTextBox1.BeginInvoke(append);
}
}
You can set the boolean stop in your click event handler:
bool stop = false;
private void button2_Click(object sender, EventArgs e)
{
stop = true;
}
Keep in mind that if you want to keep control over object instances you create consider keeping a reference to them. As you create the Process inside the thread your form can't reach it any more. If you would have made the proc an member of your form you could have called proc.StandardInput.Close() from your click event.

Related

FormClosing, OnFormClosed, ETC... Not firing on ( X ) C#

Alright, so I've got this program I'm trying to write. No company is going to rely on it or anything, so I'm not too caring that the threading here is almost positively poor practice.
My issue is that none of the "Form Closing Events" that I have found on this site and on MSDN are firing for me.
In my code, I have very hopeful console outputs that will notify me if the code has been run, but none of the events that I've found do such.
Can someone slap me into the reality of what it takes to get this to work? I know I must me missing something simple here.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
namespace CMDRunner
{
public partial class Form1 : Form
{
IDataObject clippy = Clipboard.GetDataObject();
String TClippy;
bool isRunning = true;
//Thread worker;
public Form1()
{
InitializeComponent();
try
{
TClippy = Clipboard.GetText();
}
catch (Exception e)
{
richTextBox1.Text += e.ToString() + "\n";
}
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Tick += OnTimerTick;
timer.Interval = 500;
timer.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
//worker = new Thread(KeyChecker);
//worker.SetApartmentState(ApartmentState.STA);
CheckForIllegalCrossThreadCalls = false;
//worker.Start();
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.checkBox1, "Hides anything you run.");
richTextBox2.Text += Clipboard.GetText();
}
void KeyChecker()
{
while (isRunning)
{
Thread.Sleep(40);
if ((Keyboard.GetKeyStates(Key.Return) & KeyStates.Down) > 0)
{
richTextBox1.Text += "Enter Key Clicked!!!\n";
Console.WriteLine(isRunning);
}
}
}
private void OnTimerTick(object sender, EventArgs e)
{
// I will fire the events here
if (Clipboard.ContainsText() == true && TClippy != Clipboard.GetText())
{
try
{
TClippy = Clipboard.GetText();
Clipboard.GetImage();
richTextBox2.Text = TClippy;
richTextBox3.Text = TClippy + "\n***************************************\n^^^End Clipboard item above^^^\n***************************************\n" + richTextBox3.Text;
}
catch (Exception er)
{
richTextBox1.Text += er.ToString() + "\n";
}
}
}
private void button1_Click(object sender, EventArgs e)
{
sendCommand();
}
public void sendCommand()
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
if (checkBox1.Checked)
{
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
}
else
{
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
}
startInfo.FileName = textBox1.Text;
startInfo.Arguments = textBox2.Text;
process.StartInfo = startInfo;
process.Start();
richTextBox1.Text += textBox1.Text + " \"" + textBox2.Text + "\"\n";
}
catch (System.ComponentModel.Win32Exception e)
{
Console.WriteLine(e.ToString());
richTextBox1.Text += "ERROR: Could not find: " + textBox1.Text + "\n";
}
catch (System.InvalidOperationException)
{
richTextBox1.Text += "No input provided\n" ;
}
catch (Exception e)
{
richTextBox1.Text += e.ToString() + "\n";
}
}
//UserActivityHook actHook;
/*private void Checker(object arg)
{
// Worker thread loop
for (;;)
{
if (StopRequest.WaitOne(300)) return;
richTextBox1.Text += Clipboard.GetText() + "\n";
}
}*/
//******************************************************************************************************************************
//Nothing below ever runs.....
//******************************************************************************************************************************
private void Form1_Closing(object sender, FormClosingEventArgs e)
{
isRunning = false;
Console.WriteLine(isRunning);
Console.WriteLine("CLOSING");
//worker.Join();
//e.Cancel = true;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
isRunning = false;
Console.WriteLine(isRunning);
Console.WriteLine("CLOSING");
//worker.Join();
//e.Cancel = true;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (string.Equals((sender as Button).Name, #"CloseButton"))
{
// Do something proper to CloseButton.
isRunning = false;
Console.WriteLine(isRunning);
Console.WriteLine("CLOSING");
//worker.Join();
}
else
{
isRunning = false;
Console.WriteLine(isRunning);
Console.WriteLine("CLOSING");
// Then assume that X has been clicked and act accordingly.
}
}
private void Form1_OnFormClosed(object sender, System.ComponentModel.CancelEventArgs e)
{
isRunning = false;
Console.WriteLine(isRunning);
Console.WriteLine("CLOSING");
//worker.Join();
//e.Cancel = true;
}
}
}

Reading Serial Communication Visual Studios

I need some help with Background worker. I am trying to read data from a serial port (works fine with a button) the problem is that I need to continuously read from the serial port, until someone presses a button (Close button) on the form to stop reading. I tried doing this by adding a loop, but it just ran infinitely and froze up the form. I have the following code, whenever I press the button to read, a file is created, but when I press the close port button,it says
The I/O operation has been aborted because of either a thread exit or
an application request
Any ideas on how to fix this?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.IO;
namespace SerialCommunication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
GetAvaliablePortNames();
}
bool indicator;
StreamWriter sw = new StreamWriter(#"C:\Users\slahiri\Desktop\Data\jumbo.txt");
void GetAvaliablePortNames()
{
string[] Ports = SerialPort.GetPortNames();
cmbPort.Items.AddRange(Ports);
}
private void btnOpen_Click(object sender, EventArgs e)
{
try
{
if (cmbPort.Text == "" || cmbBaud.Text == "")
{
MessageBox.Show("Please select the Port and Baud Rates");
}
else
{
serialPort1.PortName = cmbPort.Text;
serialPort1.BaudRate = Convert.ToInt32(cmbBaud.Text);
serialPort1.Open();
progressBar1.Value = 100;
groupBox2.Enabled = true;
btnRead.Enabled = true;
btnOpen.Enabled = false;
btnClose.Enabled = true;
}
}
catch (UnauthorizedAccessException)
{
txtRead.Text = "Unauthorized Acess";
}
}
private void btnClose_Click(object sender, EventArgs e)
{
serialPort1.Close();
progressBar1.Value = 0;
btnClose.Enabled = false;
btnRead.Enabled = false;
btnOpen.Enabled = true;
indicator = true;
}
private void btnRead_Click(object sender, EventArgs e)
{
if (btnRead.Text == "Read")
{
btnRead.Text = "Stop and Close Port";
progressBar1.Maximum = 1000;
progressBar1.Value = 0;
backgroundWorker1.RunWorkerAsync(progressBar1.Maximum);
indicator = false;
}
else
{
backgroundWorker1.WorkerSupportsCancellation = true;
backgroundWorker1.CancelAsync();
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
try
{
int max = (int)e.Argument;
int n = 0;
indicator = false;
do
{
//write to serial writer
sw.WriteLine(serialPort1.ReadLine());
if (backgroundWorker1.CancellationPending)
{
sw.Flush();
sw.Close();
e.Cancel = true;
break;
}
// backgroundWorker1.ReportProgress(n++);
}
while (indicator ==false);
}
catch (TimeoutException)
{
//Close Serial Writer & Messagebox
//txtRead.Text = "Time Out!";
MessageBox.Show("TimeOut Exception");
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//progressBar1.Value = e.ProgressPercentage;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
btnRead.Text = "Read";
//close serial writer
}
}
}
Since you have a do-while construct you evaluate the condition at the END!
So when you hit the Close button and close the SerialPort the backgroundworker is still active and running in the background trying to read from the SerialPort. It enters the do compartment and tries to read from a closed port, which is like running agains a closed door :) this leads to the exception.
You could solve it by
1) putting the while-evaluation on top and get rid of the do statement (making it a simple while-loop). This way the serialPort.ReadLine will not be executed anymore, because you set indicator = true; when hitting the close button.
May be in this case you should put the setting of indicator as the first line before closing the port:
private void btnClose_Click(object sender, EventArgs e)
{
try
{
indicator = true;
serialPort1.Close();
Or
2) put an extra if clause that makes sure to read only if the port is open!
if (serialPort1.IsOpen)
{
sw.WriteLine(serialPort1.ReadLine());
}

TextBox not updated in real time via BackgroundWorker with DataReceivedEventHandler enabled

I need some help with BackgroundWorker. Using Visual Studio 2015 and its windows forms
I'm new to this kind of things and really have no idea how it works etc. The code i have so far is based on various posts on here.
worker_DoWork_ not being fired at all but no idea why. I believe this is something to do with DataRceivedEventHandler because when I move the If i move the worker.DoWork += worker_DoWork_; and worker.RunWorkerAsync(); into button clicked event and disable DataReceivedEventHandler, method worker_DoWork_ is fired and I can update textBox with any static text assigned under DoSomeWork.
Also, I have no idea how to pass outline data into the text box via DoSomeWork.
Can someone help out please.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace CMD_testing
{
public partial class Form1 : Form
{
BackgroundWorker worker;
private delegate void DELEGATE();
public Form1()
{
InitializeComponent();
worker = new BackgroundWorker();
}
private void button2_Click(object sender, EventArgs e)
{
Process process;
process = new Process();
process.StartInfo.FileName = #"C:\\Project\Test\Data.bat";
process.StartInfo.UseShellExecute = false;
// process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.StartInfo.RedirectStandardInput = true;
process.Start();
process.BeginOutputReadLine();
// process.WaitForExit();
// process.Close();
}
private void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (outLine.Data != null)
{
Console.WriteLine("Im here...");
worker.DoWork += worker_DoWork_;
//worker.RunWorkerAsync();
Console.WriteLine("Im here NOW");
Console.WriteLine(outLine.Data); //its outputed fine into the console
}
}
private void worker_DoWork_(object sender, DoWorkEventArgs e)
{
Console.WriteLine("I'm at worker_DoWork_");
Delegate del = new DELEGATE(DoSomeWork);
this.Invoke(del);
}
private void DoSomeWork()
{
Thread.Sleep(1000);
textBox1.Text = "????"; // how to pass outline.Data in here
}
}
}
The problem is that you outline RunWorkerAsync();. This methods fires the DoWork-Event which handle your asynchronous code. Via the EventArgs of DoWork you can reuse your results back to your mainthread and print it to your textbox. You can get the result in the RunWorkerCompleted-Event. Here a small example based on your code:
public partial class Form1 : Form
{
BackgroundWorker worker;
public Form1()
{
InitializeComponent();
worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
worker.RunWorkerCompleted += worker_Completed;
}
private void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (outLine.Data != null)
{
if (!worker.IsBusy) //Check if Worker is working and avoid exception
worker.RunWorkerAsync();
}
}
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
//Process some Long-Running Task
Thread.Sleep(5000)
e.Result = "Done!";
}
private void worker_Completed(object sender, RunWorkerCompletedEventArgs e)
{
textbox.Text = e.Result.ToString();
}
}
}
Further you are maybe interested in Task Library which make the handling of threads easier.
UPDATE:
You say:
I want to update my Textbox in realtime.
This will print the text which your batchfile sends to Standardoutput directly in your textbox. So I don't think you need anymore.
private void OutputHandler(object sendingProcess, DataReceivedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(e.Data))
BeginInvoke(new MethodInvoker(() => { textBox1.Text = e.Data; }));
}
Thanks to #Sebi I have managed to get all issues sorted. It turns out I do not need a BackgroundWorker as some people suggested.
See the final code which works like a charm:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace CMD_testing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Process process;
process = new Process();
process.StartInfo.FileName = #"C:\\Project\Test\Other Data.bat";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.StartInfo.RedirectStandardInput = true;
process.Start();
process.BeginOutputReadLine();
process.Close();
}
private void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (outLine.Data != null)
{
BeginInvoke(new MethodInvoker(() => { textBox1.AppendText(outLine.Data + Environment.NewLine); }));
}
}
}
}

Windows Form - Running python script, redirected output delayed

I'm running a windows form with a background worker to update a textbox based on the output of a python script. Its all working pretty well, except the redirected output is not in real time; its delayed pretty significantly.
Any ideas how I can increase the redirected outputs response time?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace JiraHeartBeat
{
public partial class Form1 : Form
{
delegate void AppendTextDelegate(string text);
BackgroundWorker Worker = new BackgroundWorker();
public Form1()
{
InitializeComponent();
Worker.DoWork += new DoWorkEventHandler(Worker_DoWork);
Worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Worker_RunWorkerCompleted);
}
void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
StartButton.PerformClick();
}
private void StartButton_Click(object sender, EventArgs e)
{
if (!Worker.IsBusy)
{
Worker.RunWorkerAsync();
}
}
public void Worker_DoWork(object sender, DoWorkEventArgs e)
{
Process pro = new Process();
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.RedirectStandardError = true;
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.CreateNoWindow = true;
pro.EnableRaisingEvents = true;
pro.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived);
pro.ErrorDataReceived += new DataReceivedEventHandler(OnDataReceived);
pro.StartInfo.FileName = "C:\\Python27\\python.exe";
pro.StartInfo.Arguments = "\"C:\\Python27\\myscript.py\"";
try
{
pro.Start();
pro.BeginOutputReadLine();
pro.BeginErrorReadLine();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Thread.Sleep(5000 * 60);
}
public void OnDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
string temp = (e.Data) + Environment.NewLine;
appendText(temp);
}
}
public void appendText(string text)
{
if (ResultTextBox.InvokeRequired)
{
ResultTextBox.Invoke(new AppendTextDelegate(appendText), new object[] { text });
}
else
{
ResultTextBox.AppendText(text);
}
}
}
}
Actually, the issue is that Python does not redirect output until the script is complete. I believe IronPython will redirect while the script is running (have not tested this though), but unfortunately, regular Python must wait for the script to end before redirecting output.
Try removing the below line from the Worker_DoWork, I suspect it is delaying the execution of the RunWorkerCompleted event.
Thread.Sleep(5000 * 60);
EDIT
Since the above approach was attempted and did not solve the problem entirely I investigated a bit further and confirmed that when capturing the output from a python script the response is delayed. However, by adding a call to sys.stdout.flush() I was able to get the desired behavior. Here is the python script I used which worked successfully in my test.
import time
import sys
for x in xrange(0,11):
print x
time.sleep(1)
sys.stdout.flush()

C# capturing python.exe output and displaying it in textbox

I have worked on this issue for a while. I can capture the output(live) of the console window just fine, but I can't capture the output of a python console application in real time. I can capture the output of the python program after it has finished running, but i don't want that.
I am using process from system.diagonistics. with a background worker.
I simply want to capture the python26 output onto a text box. I have tested my program with other custom applications, and it does display the output(live).
Help please
Thanks
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace ProcessDisplayoutput
{
public partial class Form1 : Form
{
//Delegates
delegate void AppendTextDelegate(string text);
public Form1()
{
InitializeComponent();
Worker.DoWork += new DoWorkEventHandler(Worker_DoWork);
}
private void StartButton_Click(object sender, EventArgs e)
{
ResultTextBox.Clear();
if (!Worker.IsBusy)
{
Worker.RunWorkerAsync();
}
}
public void Worker_DoWork(object sender, DoWorkEventArgs e)
{
Process pro = new Process();
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.RedirectStandardError = true;
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.CreateNoWindow = true;
pro.EnableRaisingEvents = true;
pro.OutputDataReceived +=new DataReceivedEventHandler(OnDataReceived);
pro.ErrorDataReceived +=new DataReceivedEventHandler(OnDataReceived);
//Test with random program worked,
//now need to test with python
//*****************TEST 1: PASSED **************************
pro.StartInfo.FileName = "C:\\TestProcessOutput.exe";
//*****************END TEST1*******************************
//*****************TEST 2: FAILED *************************
//pro.StartInfo.FileName = "C:\\Python26\\python.exe";
//pro.StartInfo.Arguments = "\"C:\\Python26\\testScript.py\"";
//*****************END TEST2 *******************************
StreamReader sr = null;
try
{
pro.Start();
pro.BeginOutputReadLine();
//An alternative option to display the output with the same results
//sr = pro.StandardOutput;
//string line = "";
//while ((line = sr.ReadLine()) != null)
//{
// appendText(line);
// }
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void OnDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
string temp = (e.Data) + Environment.NewLine;
appendText(temp);
}
}
public void appendText(string text)
{
if (ResultTextBox.InvokeRequired)
{
ResultTextBox.Invoke(new AppendTextDelegate(appendText), new object[] { text });
}
else
{
ResultTextBox.AppendText(text);
}
}
I just ran into this question myself, and after a ton of experimenting, what worked for me was running the python process with the "-u" option, which makes the output unbuffered. With that, everything worked completely fine.
I ran into this problem while making a MiniConsole exactly for that purpose.
I used your technique with
pro.EnableRaisingEvents = true;
pro.OutputDataReceived +=new DataReceivedEventHandler(OnDataReceived);
pro.ErrorDataReceived +=new DataReceivedEventHandler(OnDataReceived);
The strange thing is that all the output was coming from ErrorDataReceived instead of OutputDataReceived (with valid commands).
So I think you're missing:
pro.BeginErrorReadLine();
Also I was starting the process in the main thread (I don't have any worker), using python27.
Here is the full start:
// executable: "c:\\python27\\python.exe", arguments: "myscript.py"
ProcessStartInfo startInfo = new ProcessStartInfo(executable, arguments);
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.WorkingDirectory = textBoxWorkingDirectory.Text;
try
{
Process p = new Process();
p.StartInfo = startInfo;
p.EnableRaisingEvents = true;
p.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(OnDataReceived);
p.Exited += new EventHandler(OnProcessExit);
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
}
I remember having a similar issue a while back and I think I did something similar to this in my .py scripts instead of using the print function:
sLog = 'Hello World!'
subprocess.Popen( 'echo ' + sLog, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True )
Not sure if I set the shell parameter to True or False though. Also not sure about all the "std" parameters. You might want to experiment a bit there.
If you're starting the Python process from your code, then THIS will make your life really easy and I think it's about the cleanest way to go.

Categories

Resources