Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Process class  RSS feed

 
Rafael Fagundes
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Well, on the topic "third part class" I�ve posted that I�m tring to use an class like this:

Process p = Runtime.getRuntime().exec("java Codigo " + request.getParameter("p1") + " " + request.getParameter("p2") + " " + request.getParameter("p3"));

BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String cod = br.readLine();

I�ve noted that the result (cod) is null (it does not create an result, so there is nothing to read) on jboss (under linux) and tomcat (under windows). But when I executed this code above on a test class on line command (DOS), and everiything worked fine.

I�ve noted also that the process under linux (jboss) is implemented by "java.lang.UNIXProcess@8d3d62", on windows (tomcat) is "java.lang.ProcessImpl@ea3932" and on line command (windows) "Win32Process@defa1a" (and this last one worked fine). Does

Some idea where is my fail? I�m I forgetting something? Am I missing some enviroment configuration question?

Thank�s in advance,
Rafael.

[ September 11, 2006: Message edited by: Rafael Fagundes ]
[ September 11, 2006: Message edited by: Rafael Fagundes ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're assuming in the above code that

1) "java" in on the PATH

2) there's a CLASSPATH, and "Codigo.class" is on it, and

3) if the arguments represent relative paths, that they're relative to the server's current working directory.

Any or all of these are likely to be bogus assumptions in your server environment, but probably valid on your desktop. In the server code, you need to use only absolute paths, use the -cp switch to Java to specify where the class is, and use an absolute path to the java executable, perhaps supplied as a configuration parameter to your application. And do more error checking!
 
Rafael Fagundes
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank�s! It started to work when I used the -cp option with the correct path.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!