File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to execute command in JRun server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to execute command in JRun server" Watch "how to execute command in JRun server" New topic
Author

how to execute command in JRun server

jenny wang
Greenhorn

Joined: Feb 23, 2001
Posts: 27
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

Joined: Jan 19, 2001
Posts: 338

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.


!_I_Know_Kung_Fu_!
jenny wang
Greenhorn

Joined: Feb 23, 2001
Posts: 27
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

Joined: Jan 31, 2000
Posts: 1467
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

Joined: Jan 19, 2001
Posts: 338

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

Joined: Feb 23, 2001
Posts: 27
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to execute command in JRun server
 
Similar Threads
Strange problem with Runtime.exec()
I want to login ( using Telnet ) to a Unix server
Regarding Executing a batch file in Java
list Linux mounted volumes
Trouble with runtime again..help!