From: Ted P. <dul...@gm...> - 2009-01-20 14:54:26
|
Hi Antonio, I'm afraid I have very little experience with Java, so I don't really know how to include Perl in a Java program. I do know that there are Perl modules that let you do the opposite, that is include Java in Perl programs .... this is most commonly done with Inline::Java, which can be found here : http://search.cpan.org/~patl/Inline-Java/ I don't know if that would give any ideas about how to include Perl in Java, but it's about the only thing I could think of to mention. Please do let us know if you figure this out, seems like potentially a very useful technique. Cordially, Ted On Fri, Jan 16, 2009 at 11:32 AM, Antonio Toral <ant...@il...> wrote: > hi, > > i'd like to use text-similarity from a java program. So from this program I > call text-similarity and then I capture its output. This is the java code: > > String command > = "text_similarity.pl --type=Text::Similarity::Overlaps --string \"" + > string1 + "\" \"" + string2 + "\""; > String result = ""; > try { > Process p = Runtime.getRuntime().exec(command); > int command_exit = p.waitFor(); > System.err.println("Command ended with value: " + command_exit); > > BufferedReader stdInput = new BufferedReader(new > InputStreamReader(p.getInputStream())); > BufferedReader stdError = new BufferedReader(new > InputStreamReader(p.getErrorStream())); > String s = null; > while ((s = stdInput.readLine()) != null) { > System.out.println("\treading result: " + s); > result += s; > } > while ((s = stdError.readLine()) != null) { > System.out.println("\tERROR: " + s); > } > } > catch (IOException e) { > e.printStackTrace(); > System.exit(-1); > } > catch (InterruptedException i) { > i.printStackTrace(); > System.exit(-2); > } > > > However it does not work! I just get the string "0". > > If I run text-similarity from the command line it works fine. > If I call from my java program a shell command (like "ls") or a "hello world" > perl script then I can capture its output, so I guess the problem is somehow > related to the way text-similarity buffers its output. I've read of people > having this kind of issues when calling perl scripts from java and someone > proposes as a solution to put this at the beginning of perl scripts: > > use IO::Handle; > STDOUT->autoflush(1); > STDERR->autoflush(1); > [http://forums.sun.com/thread.jspa?threadID=189595&forumID=31] > > however, I've also tried to put this at the beginning of text_similarity.pl > but without luck! > > Does anyone know how should I do? > > > Thanks in advance, > Antonio Toral > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > text-similarity-users mailing list > tex...@li... > https://lists.sourceforge.net/lists/listinfo/text-similarity-users > -- Ted Pedersen http://www.d.umn.edu/~tpederse |