I'm currently trying to have a simple CMD function run from my C# WPF program, and display the output in the WPF program. I think I'm close, but its not currently displaying anything. The program will open and have a confirmation that it should run the CMD file. Once 'Yes' is selected, it should open a new frame and run the program, piping it back to the frame. The CMD referenced is a simple netstat cmd. I have changed 'CreateNoWindow' to False and see the CMD opening, so it seems to be executing it.
EDIT: I left out a section of my code, whoops!
EDIT 2: Updated code to include some suggestions. No change. Could it be something to do with how I'm using a Frame?
namespace WpfApp1
{
/// <summary>
/// Interaction logic for Page3.xaml
/// </summary>
public partial class Page3 : Page
{
public Page3()
{
InitializeComponent();
}
private void Frame_Navigated(object sender, NavigationEventArgs e)
{
Task.Run(() => { Muntrainout(); });
}
public void Muntrainout()
{
System.Diagnostics.Process muntrainout = new System.Diagnostics.Process();
muntrainout.StartInfo.RedirectStandardOutput = true;
muntrainout.StartInfo.RedirectStandardError = true;
muntrainout.StartInfo.RedirectStandardInput = true;
muntrainout.StartInfo.UseShellExecute = false;
muntrainout.StartInfo.CreateNoWindow = true;
muntrainout.StartInfo.FileName = @"C:\Users\user.name\Documents\Project\Test.cmd";
muntrainout.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler((sender, e) =>
{
Console.WriteLine(e.Data);
}
);
// Error Handling
muntrainout.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler((sender, e) => { Console.WriteLine(e.Data); });
muntrainout.Start();
muntrainout.BeginOutputReadLine();
muntrainout.WaitForExit();
}
}
}