This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes not able  get a string output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "not able  get a string output" Watch "not able  get a string output" New topic
Author

not able get a string output

muusa muzammil
Greenhorn

Joined: Jan 13, 2010
Posts: 16
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

Joined: Mar 22, 2000
Posts: 12769
    
    5
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

Joined: Jan 13, 2010
Posts: 16
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

Joined: Jan 10, 2002
Posts: 61106
    
  66

Wait a minute... you're trying to read from a command line within a servlet?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

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

Joined: Jan 13, 2010
Posts: 16
yes i m trying to invoke arguments returned from command line within the servlet ...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Moving to servlets forum, in that case. And don't say anything is urgent.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5

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

Joined: Jan 13, 2010
Posts: 16
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

Joined: Aug 03, 2008
Posts: 9293
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: not able get a string output