How to read CGMiner output

0 votes

I am trying to read the CGMiner output in a C# program I am writing. I successfully read/write the standard thread input/output. But for some reason CGMiner does not write to the standard cmd window output, and I can't read it in C#. Any ideas?

This is my process start:

    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(); 
    }

This is the function I use to write to the console:

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

These are the functions I use to read from the console:

    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";
    }
Sep 12, 2018 in Blockchain by digger
• 26,740 points
1,006 views

2 answers to this question.

0 votes

You need to set the --per-device-stats flag in order for GPU stats to be written into stream

And don't forget to add this to the code in question

proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardError = true;
proc.ErrorDataReceived += (s, e) => updateConsoleOutput(e);
....
proc.Start();
proc.BeginErrorReadLine();
answered Sep 12, 2018 by slayer
• 29,350 points
0 votes

the only thing that made it work for me was

-T

here is my working code

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;
}
answered Sep 17, 2018 by Ruby

Related Questions In Blockchain

0 votes
1 answer

How to read a state after writing it into a chaincode?

Data that is 'written' in chaincode is ...READ MORE

answered May 28, 2018 in Blockchain by Perry
• 17,100 points
1,824 views
0 votes
1 answer
0 votes
1 answer

How to read file from subprocess.open in python?

you call: out, err = p.communicate() READ MORE

answered Aug 24, 2018 in Blockchain by digger
• 26,740 points
1,221 views
0 votes
1 answer
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,142 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,690 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,232 views
0 votes
1 answer

How to retrieve complete world state of hyperledger?

you can achieve this by iteration process ...READ MORE

answered Jul 5, 2018 in Blockchain by slayer
• 29,350 points
1,198 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP