This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to execute command in JRun server

 
jenny wang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code I wrote in my servlet :
Runtime runtime=Runtime.getRuntime();
Process process=null;
String file="a.txt";
String command="java Test >"+file;
try{
process=runtime.exec(command);
BufferedReader in=new BufferedReader(new FileReader(file));
......
}
But the problem is I didn't see the file created and I don't know how to debug the runtime.exec(command) code?
Anybody knows what the problem is?
Thank all your guys!
Jenny
 
Andrew Shafer
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Try fully specifying the path to where you want the file. I think that will solve the problem.
Unless you are just doing this for experiment, you would probably be better served writing Test so you can call it like a bean instead of starting up the whole runtime process.
 
jenny wang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Andrew,
I just changed the file path to absulute path such as
String file="d:/Jrun/servers/default/default-app/WEB-INF/classes/a.txt";
But it didn't solve the problem. the file still didn't get created.
Jenny
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jenny,
I have JRun3.0 Developer edition installed my machine. Just created a ping.jsp to test your need. I used the command "java " alone to see our luck/ Got all the instructions given by "java" program (all those Usage:..... lines") and captured them. Basically whatever comes out of Process we can capture and work with the output.
All those System.out.printlns will be stored in C:\Program Files\Allaire\JRun\logs\default-out.log file. Here I installed in C:\ProgramFiles dir.
The sample code I used is

I tried with another test "java PingPing" which will just 2 System.out.printlns. I put the PingPing.class 's dir in classPath and tested with Tomcat. Able to see those printlns in Dos prompt. When I tried the same with JRun didn't get any in log file.
I suspect we have to change the classpath of JRun to include PingPing's dir also. I tried with JRun AdminServer web appln's Java Appln Management COnsole ---Java Settings---Classpath-- added this new dir. Quit both admin and default servers and loaded again. But couldn't get the output for "java PingPing" in log file. Just a Dos Window appears for a second and disappears.
I suspect JRun didn't take the new classpath.
I know this post doesn't help that much. If I get any progress , post it here!
regds
maha anna
 
Andrew Shafer
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Curious, what happens if you just try:
java Test > a.txt
at the command line?
I had a problem calling a C++ program that generated a file with Runtime.exec(). I couldn't find the file anywhere, but the program said the results were calculated. When I fully specified the path, the problem was solved.
My experience is mainly running Tomcat on Linux, sorry it didn't help.
Please post how you solve the problem.
Andrew
 
jenny wang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear maha,andrew:

I typed "java Test >a.txt" in command line and got "a.txt" file showed up and I am able to drag the data from this file into my web page. But seems that Jrun server won't let your code share its "runtime". I will continue testing this code.
Thanks very much for your help and shared infomation.
Jenny
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic