• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able get a string output

 
muusa muzammil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends.here out is the response object .i am trying to return a string from the command line but i am getting the output as an object that is @some numbers .actually i m trying to read this string from the command line and returning it to the browser.


try
{

String line;
// String path="/home/muzammil/apache-tomcat-6.0.18/work/Catalina/localhost/remote_compile/"+filen[0];
Process p = Runtime.getRuntime().exec
("java -classpath /home/muzammil/apache-tomcat-6.0.18/work/Catalina/localhost/remote_compile/" +filen[0]);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
line=input.readLine();
while (line != null)
{
out.println("<html>");
out.println("<body>");
out.println("Output is:" +line );

out.println("</body></html>");

out.close();
}

}
catch (Exception err)
{
err.printStackTrace();
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that code worked it would hang in the while loop since you never read the next line.

Furthermore you have set yourself up for mysterious bugs by exec() ing without handling the stderr character stream.

Bill
 
muusa muzammil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:If that code worked it would hang in the while loop since you never read the next line.

Furthermore you have set yourself up for mysterious bugs by exec() ing without handling the stderr character stream.

Bill

so how is it that it is going to work .can you give me an example
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait a minute... you're trying to read from a command line within a servlet?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
muusa muzammil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i m trying to invoke arguments returned from command line within the servlet ...
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to servlets forum, in that case. And don't say anything is urgent.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Where is filen[0] coming from? Are you really trying to read the Tomcat start command line?

The JavaDocs for Process explain about handling the stdErr and stdOut streams from an exec().

I am suspecting a deep misunderstanding about how servlets and servlet containers work, read up on servlet life cycles.

Bill
 
muusa muzammil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the solution to that I used the name of static class instead of filen[0] n got the output.
changed it to dynamic using filen[0].toString().
and nw it is working perfectly
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
muusa muzammil wrote:I got the solution to that I used the name of static class instead of filen[0] n got the output.
and nw it is working perfectly

Please UseRealWords on javaranch...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic