2016-04-06 147 views
0

我正在編寫一個應用程序,顯示您在Ethereum(像比特幣這樣的加密貨幣)中的當前哈希率,並且我需要以某種方式從正在運行的命令行獲取連續輸出。這是我到目前爲止,但它不打印到程序輸出:C#WPF讀取控制檯輸出

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

什麼是不適用於此代碼?我猜測事件處理程序有些東西搞砸了,但我不知道是什麼。

+0

你打電話的任何進程?像Process aNewProcess = new Process(); – bluetoothfx

+0

很難說這裏發生了什麼,代碼不多。 –

+0

我想你需要給我們更多的細節。如果你能夠。 – bluetoothfx

回答

0

複製並粘貼到您的代碼,我修改爲你:

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

討厭說這個,但是...這沒有奏效D: – MattyAB

+0

我沒有在程序中得到任何輸出,只有線程0x1448退出了代碼0(0x0)' – MattyAB

+0

這裏工作正常。 ..給屏幕排序等待 – bluetoothfx