2014-01-27 52 views
0

我正在尝试在我正在编写的C#程序中读取CGMiner输出。我成功读取/写入标准线程输入/输出。但由于某种原因,CGMiner不会写入标准的cmd窗口输出,而且我也无法在C#中读取它。有任何想法吗?如何阅读CGMiner输出?

这是我的过程开始:

public void start() { 
     proc = new Process(); 
     proc.StartInfo.FileName = "CMD.exe"; 
     proc.StartInfo.RedirectStandardInput = true; 
     proc.StartInfo.RedirectStandardOutput = true; 
     proc.StartInfo.UseShellExecute = false; 
     proc.OutputDataReceived += (s, e) => updateConsoleOutput(e); 
     proc.Start(); 
     proc.BeginOutputReadLine(); 
    } 

这是我使用写入控制台功能:

public void RunCommand(string cmd = "") { 
     if (cmd.Length > 0) { 
      ConsoleInput = cmd; 
     } 
     StreamWriter myStreamWriter = proc.StandardInput; 
     myStreamWriter.WriteLine(ConsoleInput); 
     myStreamWriter.Flush(); 
     ConsoleInput = String.Empty; 
    } 

这些都是我用从控制台读取功能:

public delegate void consoleOutputCallback(string message); 
    private void updateConsoleOutput(DataReceivedEventArgs outLine) { 
     if (!String.IsNullOrEmpty(outLine.Data)) { 
      this.Dispatcher.Invoke(
       new consoleOutputCallback(updateConsoleText), 
       new object[] { outLine.Data } 
      ); 
     } 
    } 
    public void updateConsoleText(string message) { 
     this.OutputBlock.Text += message + "\n"; 
    } 

提示:不知道它是否有帮助,但CGMiner会覆盖整个控制台窗口,并且光标一直在留在左上角,不动。运行CGMiner之前的所有命令都被覆盖。


忘了补充,这是控制台命令我使用:

cd C:\cgminer\ 
del *.bin 
cgminer.exe -o stratum+tcp://global.wemineltc.com:3335 -O yongke.1:x -g 2 
+0

请不要包含关于问题标题中使用的语言的信息,除非在没有它的情况下没有意义。标签用于此目的。 –

回答

0

您需要设置--per设备提供的统计标志,以便GPU统计数据被写入到流

而且不要忘记添加这代码有问题

proc.StartInfo.CreateNoWindow = true; 
proc.StartInfo.RedirectStandardError = true; 
proc.ErrorDataReceived += (s, e) => updateConsoleOutput(e); 
.... 
proc.Start(); 
proc.BeginErrorReadLine(); 

大多数矿工的使用非标准错误流,而不是非标准输出流(写两个输出数据和错误),由于某种原因..

+0

似乎并不适用于我 –

+0

@Michael Rudner Evanchik我已经更新了我的答案 - 现在检查它 – bairog

+0

@Michael Rudner Evanchik我忘记了'proc.BeginErrorReadLine()' - 我再次更新了我的答案 – bairog

0

,使得它的工作对我来说是唯一

-T 

这里是我的工作代码

Task StartGPUMiner(object set) 
    { 
     MinerParams m = new MinerParams(); 
     m = (MinerParams)set; 
     var tcs = new TaskCompletionSource<object>(); 
     Process p = new Process(); 
     ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo(); 
     start.FileName = m.ApplicationPath + "\\cgminer\\cgminer.exe"; 
     start.Arguments = " -I " + m.GpuIntisity + " -T --scrypt -o " + m.sProtocol + m.ServerName + ":" + m.ServerPort + " -u " + m.UserName + "." + m.WorkerName + " -p " + m.ThePassword + " " + m.GpuParams; 
     start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
     start.RedirectStandardOutput = true; 
     start.UseShellExecute = false; 
     start.CreateNoWindow = true; 

     var proc = Process.Start(start); 
     proc.OutputDataReceived += (s, e) => 
     { 
      try 
      { 
       this.Invoke((Action)delegate 
       { 
        txtLog.Text += (e.Data + Environment.NewLine); 
       }); 
      } 
      catch { } 
     }; 

     try 
     { 
      proc.Exited += (s, e) => tcs.SetResult(null); 
      proc.EnableRaisingEvents = true; 
      proc.BeginOutputReadLine(); 
     } 
     catch { } 
      return tcs.Task; 
} 
+1

请详细说明答案。 –

+0

我试过** - T **或** - 纯文本**标志而不是** - 每设备统计**。对我来说,它只适用于基准模式。如果通过** stratum + tcp **连接 - 我收到的最后一个数据是“探测活动池”。 ** Win 7超级64位SP1 + .NET 4.0 + cgminer 3.7.2 ** – bairog