title: Android handle real-time output from executable through EventBus (greenbot)
body: <p>To run the executable and get the real-time output I'm using the following code (with <code>String[] command = new String[]{"/a.out"};</code>):</p>
  
  <pre><code>public static void execute(String... command) {
      try {
          ProcessBuilder builder = new ProcessBuilder(command);
          builder.redirectErrorStream(true);
          final Process proc = builder.start();
          new Thread(new Runnable() {
              public void run() {
                  BufferedReader reader = null;
                  try {
                      reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                      String line = null;
                      while ((line = reader.readLine()) != null) {
                          EventBus.getDefault().post(new MessageEvent(line+"\n"));
                      }
                  } catch (Exception e) {
                      // TODO
                  } finally {
                      if (reader != null) {
                          try {
                              reader.close();
                          } catch (IOException e) {
                              // ignore
                          }
                      }
                  }
              }
          }).start();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>The command should be executed inside a service:</p>
  
  <pre><code>public class Service extends IntentService {
  ...
  
      @Override
      protected void onHandleIntent(Intent intent) {
          String[] command = new String[]{"/a.out"};
          Class.execute(command);
      }
  
  }
  </code></pre>
  
  <p>But I only get one line as an output, nothing more, but it should be hundreds of them. I already tried it on my computer by replacing <code>EventBus.getDefault().post(new MessageEvent(line+"\n"));</code> with <code>System.out.println(line);</code> and it works just fine.</p>
  
  <p>Additional information: Subscriber handles EventBus through:</p>
  
  <pre><code>@Subscribe(threadMode = ThreadMode.MAIN)
  public void onMessageEvent(MessageEvent event) {
      tv.append(event.getMessage());
  }
  
  @Override
  public void onStart() {
      super.onStart();
      EventBus.getDefault().register(this);
  }
  
  @Override
  public void onStop() {
      EventBus.getDefault().unregister(this);
      super.onStop();
  }
  </code></pre>
  
  <p>And tv is a TextView: <code>TextView tv = (TextView)findViewById(R.id.TextView);</code></p>
  
  <p>This structure was tested with a simple method, which in the following shown. It updated the TextView and there was more than one line passed to the TextView. So I guess it must be something inside my execution method.</p>
  
  <pre><code>public static void test() {
      for(int i = 0; i&lt;500000; i++)
          EventBus.getDefault().post(new MessageEvent(i+"\n"));
  }
  </code></pre>
  
  <p>Why does the EventBus only passes one line? What can I change to get the expected result?</p>
  
  <p>Edit: Changing <code>onMessageEvent()</code> to:</p>
  
  <pre><code>public void onMessageEvent(MessageEvent event) {
      Log.i("Activity",event.getMessage());
  }
  </code></pre>
  
  <p>Also just one line.</p>
  
  <p>Tested it with another executable, now it works just fine, any idea why it works now?</p>