基本上我试图启动一个进程并获得输出。该程序是 minerd.exe(比特币 cpu 矿工)https://github.com/pooler/cpuminer供参考我尝试过这样的事情:
private void StartMining()
{
Process p = new Process();
StreamWriter sw;
StreamReader sr;
StreamReader err;
ProcessStartInfo psI = new ProcessStartInfo(@"miners\minerd.exe");
psI.Arguments = "-o " + miner.PoolIp + ":" + miner.PoolServerPort + " -O " + miner.PoolUsername + ":" + miner.PoolPassword;
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;
p.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(proc_ErrorDataReceived);
p.Start();
p.BeginOutputReadLine();
}
private void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
WriteLogWindow(e.Data, Color.Green);
}
private void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
WriteLogWindow(e.Data, Color.Red);
}
private delegate void DelegateInsertNewLineToLogRichTextBox(string text, Color color);
void WriteLogWindow(string text, Color color)
{
if (this.richTextBox1.InvokeRequired)
{
DelegateInsertNewLineToLogRichTextBox method = new DelegateInsertNewLineToLogRichTextBox(InvokedInsertNewLineToLgoRichTextBox);
Invoke(method, new object[2] { text, color });
}
else
{
InvokedInsertNewLineToLgoRichTextBox(text, color);
}
}
private void InvokedInsertNewLineToLgoRichTextBox(string message, Color color)
{
richTextBox1.Font = new Font("Arial", 8F, FontStyle.Bold);
richTextBox1.SelectionColor = color;
richTextBox1.SelectedText = Environment.NewLine + message + "\t" + DateTime.Now.ToString("HH:mm:ss d/M/yyyy");
richTextBox1.ScrollToCaret();
}
矿工似乎在工作,但我没有得到任何输出。
提前感谢您的任何建议