I use Eclipse to develop a Java program and I believe that I will add a parameter to my program to parse stdin if there are no arguments. (otherwise it parses the file)
I am having problems if I execute "somecommand | java -jar myjar.jar" and go for debugging ... then I realized that I don’t know how to start the process in Eclipse like this. And if I run it on the command line, I can’t connect to the running process, since the process starts right away.
Any suggestions for debugging?
edit : see, the fact is that I first wrote my program to accept the file name argument. Then I thought it would be useful to accept stdin as well, so I made an abstract InputStream from my program (as Mr. Queue suggests). It works fine in the file ( java -jar myjar.jar myfile ) but does not work when I run type myfile | java -jar myjar.jar type myfile | java -jar myjar.jar . I suspect there is something else in the two scenarios (eof detection different?), But I really would like to debug.
// overall program structure follows: public static void doit(InputStream is) { ... } public static void main(String[] args) { if (args.length > 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); } }
java eclipse stdin
Jason S Oct 16 '09 at 22:38 2009-10-16 22:38
source share