我正在尝试在我正在编写的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
请不要包含关于问题标题中使用的语言的信息,除非在没有它的情况下没有意义。标签用于此目的。 –