WPF вывод ответа из командной строки

Всем привет! Не выводится на экран ответ от командной строки при запуске JLink.exe,при нажатии кнопки "ReadMemory" ничего не происходит. Но если после этого ввести команду "exit" выводятся все операции, произведенные в командной строке. Как можно это исправить и почему это происходит?

public partial class MainWindow : Window
{
    Process jLinkProcess = new Process();
    
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        jLinkProcess.StartInfo = new ProcessStartInfo(@"C:\Program Files\SEGGER\JLink\JLink.exe");
        jLinkProcess.StartInfo.UseShellExecute = false;
        jLinkProcess.StartInfo.RedirectStandardInput = true;
        jLinkProcess.StartInfo.RedirectStandardOutput = true;
        jLinkProcess.StartInfo.RedirectStandardError = true;
        jLinkProcess.StartInfo.CreateNoWindow = true;
        jLinkProcess.OutputDataReceived += CmdProcess_OutputDataReceived;
        jLinkProcess.ErrorDataReceived += CmdProcess_ErrorDataReceived;
        jLinkProcess.Start();
        jLinkProcess.BeginOutputReadLine();
        jLinkProcess.BeginErrorReadLine();
        jLinkProcess.StandardInput.WriteLine("connect");
        jLinkProcess.StandardInput.WriteLine("NRF52811_XXAA");
        jLinkProcess.StandardInput.WriteLine("SWD");
        jLinkProcess.StandardInput.WriteLine("4000");
    }

    private void CmdProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
    {
        Dispatcher.Invoke(() =>
        {
            TextBox2.Text += e.Data + "\r\n";
            TextBox2.ScrollToEnd();
        });
    }

    private void CmdProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        Dispatcher.Invoke(() =>
        {
            TextBox2.Text += e.Data + "\r\n";
            TextBox2.ScrollToEnd();
        });
    }

    private void TextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (sender is TextBox textBox && e.Key == Key.Enter)
        {
            jLinkProcess.StandardInput.WriteLine(textBox.Text);
            textBox.Text = string.Empty;
            e.Handled = true;
        }
    }

    private void ReadMemory(object sender, RoutedEventArgs e)
    {
        string mac = "mem 10000060,8";
        jLinkProcess.StandardInput.WriteLine(mac);
    }
}

Ответы (0 шт):