アプリ版:「スタンプのみでお礼する」機能のリリースについて

C#を使って自己解凍ファイル(gui)を作りたいです。
中にunrar等の解凍用のexe(コンソールアプリ)を埋め込んで、
ボタンをクリックしたら、中のexeにカレントディレクトリに指定したファイルを解凍するようなdosコマンドを出力して実行させたいです。
実行中、限られた行だけのログを.NETのテキストボックスに表示させたいです。
何かいい方法はないでしょうか?

質問者からの補足コメント

  • これをテキストボックス内に表示するにはどうすればいいのですか?

    No.1の回答に寄せられた補足コメントです。 補足日時:2019/03/19 14:50

A 回答 (2件)

using System;


using System.Text;
using System.Windows.Forms;

namespace Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.OutputDataReceived += OutputDataReceived;

p.StartInfo.FileName = Environment.GetEnvironmentVariable("ComSpec");
p.StartInfo.RedirectStandardInput = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = @"/c dir c:\ /w";

p.Start();
p.BeginOutputReadLine();

p.WaitForExit();
p.Close();
}

private async void OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
Action action = () =>
{
var sb = new StringBuilder(textBox1.Text);
sb.Append(e.Data + Environment.NewLine);
textBox1.Text = sb.ToString();
};

this.BeginInvoke(action);
}
}
}
    • good
    • 0
この回答へのお礼

ありがとうございました!
とても助かりました。

お礼日時:2019/03/19 23:36

これじゃダメですか。


[非同期で出力データを取得する]項。
https://dobon.net/vb/dotnet/process/standardoutp …
この回答への補足あり
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!