Napisalem program w pythonie i go skompilowalem do exe. Pierwszy raz cos takiego robie zeby tekst z terminala miec w aplikacji. Problem jest taki ze aplikacja(terminal) sie uruchamia i nie przechwytuje tekstu do richtextbox. Pierwszy raz cos takiego robie i teraz jak jest to sie uruchamia i nie wypisuje. Ale jak juz chce przez backgroundworkera to juz wgl nic nie rusza.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Kombajn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BC.exe");
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
// startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;
process.EnableRaisingEvents = true;
StringBuilder outputBuilder = new StringBuilder();
process.OutputDataReceived += (o, ee) =>
{
if (ee.Data != null)
{
outputBuilder.AppendLine(ee.Data);
// update RichTextBox control with the new output
richTextBox1.Invoke((MethodInvoker)delegate
{
richTextBox1.AppendText(ee.Data + Environment.NewLine);
});
}
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
//backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BC.exe");
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
//startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;
process.EnableRaisingEvents = true;
StringBuilder outputBuilder = new StringBuilder();
process.Start();
while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();
outputBuilder.AppendLine(line);
backgroundWorker1.ReportProgress(0, line);
}
process.WaitForExit();
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
string line = (string)e.UserState;
richTextBox1.AppendText(line + Environment.NewLine);
}
}
}