Forum

Пожалуйста or Регистрация для создания сообщений и тем.

PowerShell и CMD

Добрый день!

Наткнулся на ваше видео Видео
Делаю как в видео, но при выполнении крашится:

Код

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace CMDandPowerShell

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}


private void Button1_Click(object sender, EventArgs e)

{


Process process2 = Process.Start(new ProcessStartInfo

{

FileName = "powershell",

Arguments = "/command get-appxpackage | ft name",

UseShellExecute = false,

CreateNoWindow = true,

RedirectStandardOutput = true

});

process2.BeginOutputReadLine();

process2.OutputDataReceived += (s, w) => { textBox1.Text += w.Data + Environment.NewLine; };

//textBox1.Text = "";

//textBox1.Text = process2.StandardOutput.ReadToEnd(); //Simple Output

}



private void Button2_Click(object sender, EventArgs e)

{

Process process = Process.Start(new ProcessStartInfo

{

FileName = "cmd",

Arguments = "/c chcp 65001 & ipconfig & exit",

UseShellExecute = false,

CreateNoWindow = true,

RedirectStandardOutput = true,

});

//process.BeginOutputReadLine();

//process.OutputDataReceived += (s, a) => { label1.Text += a.Data + "\n"; };

textBox1.Text = "";

textBox1.Text = process.StandardOutput.ReadToEnd(); //Simple Output

}

}

}

Если выводить СкопированоtextBox1.Text = process.StandardOutput.ReadToEnd(); все ок.

Подскажите как исправить что бы заработало, заранее спасибо!

Добрый 🖐
Переключите режим сборки на Release, а затем запустите. Смотрите последовательно уроки, там будет про потоки очень подробно.