• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to execute command in JRun server

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic