I did this question in here because I was aspecting that I was not the first crazy man doing something like this. I'm a perl programmer not a java programmer.
I know that I'll have problems calling one from the other like this. Probabli the final release will be a Server/Client application to avoid this issue and give me the fridum to have interfaces in diferent machines in diferent countries, but for now I would be glade to have it simple. What I give was a test script, in the real world the script takes 15 minutes to 3 hours at least to run. I tryed to do the interface with perlTK and the results was not very OS like. I would be hapy if someone can help me. I need to run something like: perl -e 'print "ola\n" foreach (1..100)'. Thanks Marcos -----Original Message----- From: R. Joseph Newton [mailto:[EMAIL PROTECTED] Sent: Thursday, March 11, 2004 3:48 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Some java some perl [EMAIL PROTECTED] wrote: > I'm doing one interface in java that will call some perl scripts. I need to > catch the output and I don't know how to do it. > > If I execute the 'ls' command my java program finnish if I call the perl my > program don't finnish. What am I missing? What are you expecting from your call to Perl? Note that shelling out has the same dangers with Java as with Perl. > > > import java.io.DataInputStream; > import java.io.IOException; > > public class Test { > public static void main(String[] args) { > try { > Runtime r = Runtime.getRuntime(); > > String[] aStr = {"-e", "'print(\"Ola\n\") foreach (1..100);'"}; > > Process p = r.exec("perl", aStr); You told the system to open the perl compiler here. You may also have Offered it 100 lines like this: "Ola ""Ola Which Perl would have a very hard time interpreting as code. > > //Process p = r.exec("ls"); > > DataInputStream strm = new DataInputStream(p.getInputStream()); > > String str; > while ((str = strm.readLine()) != null){ > System.out.println(str); > } > } catch (IOException e) { > e.printStackTrace(); > } > } > } > > Thanks > Marcos The code above is straight Java. Although it does inicdentally call the Perl interpreter, it is not presented with any further directions, and therefore does nothing. It is probably not the right place to discuss the Java Runtime::exec function. That would be more appropriate on a Java list [use Google to find one] For what it is worth, perl is generally called with a script name or code as the first parameter.. Please learn how to use each language well on its own before you try to develop cross-platform programs. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>