W
wkaibigan
Hi there
I have currently have the code shown below that runs a process and
redirects the output to a listbox. It all works as expected which is
great, however, it is often likely that more than one process will be
required to run, usually up to 4. What I would like is to redirect
the output of each of these processes to individual listboxes.
Currently, a new process is created using
Process app = new Process();
This means that only the output for the last process run gets shown in
the listbox using the current code.
My question is, rather than repeat the same code 4 times using a
different process name for each, is it possible to automatically
change the process name each time the code is called. e.g. when first
run Process app1 = new Process() ; then next run it will be Process
app2 = new Process ; etc.
Hope I made it clear.
Thanks.
Process app = new Process();
string runcommand = textBox1.Text;
app.StartInfo.FileName = version.Location;
app.StartInfo.Arguments = tuflowruntype;
app.StartInfo.RedirectStandardError = true;
app.StartInfo.RedirectStandardOutput = true;
app.StartInfo.CreateNoWindow = true;
app.EnableRaisingEvents = true;
app.ErrorDataReceived += new
DataReceivedEventHandler(app_ErrorDataReceived);
app.OutputDataReceived += new
DataReceivedEventHandler(app_OutputDataReceived);
app.StartInfo.UseShellExecute = false;
app.Start();
textBox3.Text = app.Id.ToString();
listBox1.Items.Add(app.Id.ToString());
switch (comboBox2.SelectedItem.ToString())
{
case "High":
app.PriorityClass =
ProcessPriorityClass.High;
break;
case "Normal":
app.PriorityClass =
ProcessPriorityClass.Normal;
break;
case "Low":
app.PriorityClass =
ProcessPriorityClass.Idle;
break;
}
switch (comboBox3.SelectedItem.ToString())
{
case "All":
app.ProcessorAffinity =
(System.IntPtr)allcpus;
break;
case "0":
app.ProcessorAffinity =
(System.IntPtr)cpu0;
break;
case "1":
app.ProcessorAffinity =
(System.IntPtr)cpu1;
break;
case "2":
app.ProcessorAffinity =
(System.IntPtr)cpu2;
break;
case "3":
app.ProcessorAffinity =
(System.IntPtr)cpu3;
break;
case "4":
app.ProcessorAffinity =
(System.IntPtr)cpu4;
break;
case "5":
app.ProcessorAffinity =
(System.IntPtr)cpu5;
break;
case "6":
app.ProcessorAffinity =
(System.IntPtr)cpu6;
break;
case "7":
app.ProcessorAffinity =
(System.IntPtr)cpu7;
break;
}
app.BeginErrorReadLine();
app.BeginOutputReadLine();
I have currently have the code shown below that runs a process and
redirects the output to a listbox. It all works as expected which is
great, however, it is often likely that more than one process will be
required to run, usually up to 4. What I would like is to redirect
the output of each of these processes to individual listboxes.
Currently, a new process is created using
Process app = new Process();
This means that only the output for the last process run gets shown in
the listbox using the current code.
My question is, rather than repeat the same code 4 times using a
different process name for each, is it possible to automatically
change the process name each time the code is called. e.g. when first
run Process app1 = new Process() ; then next run it will be Process
app2 = new Process ; etc.
Hope I made it clear.
Thanks.
Process app = new Process();
string runcommand = textBox1.Text;
app.StartInfo.FileName = version.Location;
app.StartInfo.Arguments = tuflowruntype;
app.StartInfo.RedirectStandardError = true;
app.StartInfo.RedirectStandardOutput = true;
app.StartInfo.CreateNoWindow = true;
app.EnableRaisingEvents = true;
app.ErrorDataReceived += new
DataReceivedEventHandler(app_ErrorDataReceived);
app.OutputDataReceived += new
DataReceivedEventHandler(app_OutputDataReceived);
app.StartInfo.UseShellExecute = false;
app.Start();
textBox3.Text = app.Id.ToString();
listBox1.Items.Add(app.Id.ToString());
switch (comboBox2.SelectedItem.ToString())
{
case "High":
app.PriorityClass =
ProcessPriorityClass.High;
break;
case "Normal":
app.PriorityClass =
ProcessPriorityClass.Normal;
break;
case "Low":
app.PriorityClass =
ProcessPriorityClass.Idle;
break;
}
switch (comboBox3.SelectedItem.ToString())
{
case "All":
app.ProcessorAffinity =
(System.IntPtr)allcpus;
break;
case "0":
app.ProcessorAffinity =
(System.IntPtr)cpu0;
break;
case "1":
app.ProcessorAffinity =
(System.IntPtr)cpu1;
break;
case "2":
app.ProcessorAffinity =
(System.IntPtr)cpu2;
break;
case "3":
app.ProcessorAffinity =
(System.IntPtr)cpu3;
break;
case "4":
app.ProcessorAffinity =
(System.IntPtr)cpu4;
break;
case "5":
app.ProcessorAffinity =
(System.IntPtr)cpu5;
break;
case "6":
app.ProcessorAffinity =
(System.IntPtr)cpu6;
break;
case "7":
app.ProcessorAffinity =
(System.IntPtr)cpu7;
break;
}
app.BeginErrorReadLine();
app.BeginOutputReadLine();