A
Andrus
Long-running backup program mybackup.exe wrotes status messages to stderr
How to show messages written to stderr if this program is running ?
I tried code below but it shows stderr output only after program is
completed.
Andrus.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
class DBCreate
{
internal string msg;
internal void dbCreate()
{
ProcessStartInfo pinfo = new ProcessStartInfo();
pinfo.ErrorDialog = true;
pinfo.FileName = Environment.CurrentDirectory +
"\\mybackup.exe";
pinfo.WindowStyle = ProcessWindowStyle.Maximized;
pinfo.RedirectStandardError = true;
pinfo.UseShellExecute = false;
pinfo.RedirectStandardOutput = true;
Process p = new Process();
p.EnableRaisingEvents = true;
p.StartInfo = pinfo;
p.Start();
msg = p.StandardError.ReadToEnd();
while (!p.HasExited)
System.Threading.Thread.Sleep(1000);
p.WaitForExit();
p.Close();
}
}
public static class BackupCopy
{
public static void Run()
{
var bw = new BackupbackgroundWorker();
bw.RunWorkerAsync();
}
}
class BackupbackgroundWorker : BackgroundWorker
{
string msg;
DBCreate db;
protected override void OnDoWork(DoWorkEventArgs e)
{
db = new DBCreate();
db.dbCreate();
msg = db.msg;
base.OnDoWork(e);
}
protected override void
OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
{
base.OnRunWorkerCompleted(e);
MessageBox.Show( msg );
}
}
How to show messages written to stderr if this program is running ?
I tried code below but it shows stderr output only after program is
completed.
Andrus.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
class DBCreate
{
internal string msg;
internal void dbCreate()
{
ProcessStartInfo pinfo = new ProcessStartInfo();
pinfo.ErrorDialog = true;
pinfo.FileName = Environment.CurrentDirectory +
"\\mybackup.exe";
pinfo.WindowStyle = ProcessWindowStyle.Maximized;
pinfo.RedirectStandardError = true;
pinfo.UseShellExecute = false;
pinfo.RedirectStandardOutput = true;
Process p = new Process();
p.EnableRaisingEvents = true;
p.StartInfo = pinfo;
p.Start();
msg = p.StandardError.ReadToEnd();
while (!p.HasExited)
System.Threading.Thread.Sleep(1000);
p.WaitForExit();
p.Close();
}
}
public static class BackupCopy
{
public static void Run()
{
var bw = new BackupbackgroundWorker();
bw.RunWorkerAsync();
}
}
class BackupbackgroundWorker : BackgroundWorker
{
string msg;
DBCreate db;
protected override void OnDoWork(DoWorkEventArgs e)
{
db = new DBCreate();
db.dbCreate();
msg = db.msg;
base.OnDoWork(e);
}
protected override void
OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
{
base.OnRunWorkerCompleted(e);
MessageBox.Show( msg );
}
}