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
• 27,620 points
36 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,040 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
• 16,450 points
166 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
• 27,620 points
32 views
0 votes
1 answer
0 votes
1 answer

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

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
42 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
61 views
0 votes
1 answer
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,040 points
135 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.