title: Java+Eclipse: how do you debug a java program that is receiving piped/redirected stdin?
body: <p>I'm using Eclipse to develop a Java program, and figured I'd add an option to my program to parse stdin if there are no arguments. (otherwise it parses a file)</p>
  
  <p>I am having problems if I execute <code>"somecommand | java -jar myjar.jar"</code> and went to debug... then realized I don't know how to start a process in Eclipse like that. And if I run it on the command prompt, I can't attach to a running process since the process starts immediately.</p>
  
  <p>Any suggestions on how to debug?</p>
  
  <p><strong>edit</strong>: see, the thing is, I wrote my program originally to take a filename argument. Then I figured it would be useful for it to take stdin as well, so I <em>did</em> abstract InputStream out of my program (as Mr. Queue suggests). It works fine operating on a file (<code>java -jar myjar.jar myfile</code>), but not operating when I run <code>type myfile | java -jar myjar.jar</code>. I suspect that there's something different in the two scenarios (eof detection is different?)  but I really would like to debug.</p>
  
  <pre><code>// overall program structure follows:
  
  public static void doit(InputStream is)
  {
      ...
  }
  
  public static void main(String[] args)
  {
      if (args.length &gt; 0)
      {
          // this leaves out the try-catch-finally block,
          // but you get the idea. 
          FileInputStream fis = new FileInputStream(args[0]);
          doit(fis);
          fis.close();
      }
      else
      {
          doit(System.in);
      }
  }
  </code></pre>