0

I'm writing an app that displays your current hashrate in Ethereum (A cryptocurrency like Bitcoin), and I need to somehow get the continuous output from the Command line that is running. This is what I have so far, but it is not printing to the program output:

 pProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
    // Prepend line numbers to each line of the output.
    if (!String.IsNullOrEmpty(e.Data))
    {
        System.Console.Write(e.Data);
    }
});

//Wait for process to finish
pProcess.WaitForExit();

What is not working with this code? I'm guessing there's something messed up with the event handler, but I don't know what.

11
  • Are you calling any process?? Like Process aNewProcess = new Process(); Commented Apr 6, 2016 at 19:55
  • Hard to tell what's going on here, there's not much code. Commented Apr 6, 2016 at 19:57
  • I think you need to give us more details. If you please. Commented Apr 6, 2016 at 19:58
  • sorry, here's a download of the whole project: mega.nz/#F!P1cW2JRI Commented Apr 6, 2016 at 19:58
  • I want to have en event triggered when a new line gets written to the console, as well as the line itself being sent to a string so that it can be parsed and used later on in the code. Commented Apr 6, 2016 at 20:00

1 Answer 1

1

Copy and paste it to your code I modified it for you:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;

    namespace ETHMinerVisualiser
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }

            private void MineButton_Click(object sender, RoutedEventArgs e)
            {
                Task.Run(() => { startMining(); });
            }

            public void startMining()
            {
                //Create process
                System.Diagnostics.Process pProcess = new System.Diagnostics.Process();

                //strCommand is path and file name of command to run
                pProcess.StartInfo.FileName = @"E:/Documents/ETH/ETHMinerVisualiser/ethminer-cuda-0.9.41-new/ethminer.exe";

                //strCommandParameters are parameters to pass to program
                pProcess.StartInfo.Arguments = "-F eu1.ethermine.org:5555/0x9c3f6281b123541f10c9bf37a8f273aa2a774d17.PCGPU -C";

                pProcess.StartInfo.UseShellExecute = false;


                //Set output of program to be written to process output stream
                pProcess.StartInfo.RedirectStandardOutput = true;

                //Optional
                pProcess.StartInfo.WorkingDirectory = "";

                //Start the process
                pProcess.Start();

                //pProcess.StartInfo.CreateNoWindow = true;

                //pProcess.BeginOutputReadLine();

                pProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
                {
                    // Prepend line numbers to each line of the output.
                    if (!String.IsNullOrEmpty(e.Data))
                    {
                        //System.Console.Write(e.Data);                   
                        Debug.WriteLine(e.Data);
                    }
                });

                //Wait for process to finish
                pProcess.BeginOutputReadLine();

                pProcess.WaitForExit();
            }
        }
    }
Sign up to request clarification or add additional context in comments.

4 Comments

I don't get any output in the program out, only 'The thread 0x1448 has exited with code 0 (0x0)'
Correct this....I think you copied my location....pProcess.StartInfo.FileName = @"E:/Documents/ETH/ETHMinerVisualiser/ethminer-cuda-0.9.41-new/ethminer.exe";
but... that's not what I want... I want the Program output mirroring the cmd output. What did you think I meant? did I not explain it correctly? sorry if so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.