aspose file tools
The moose likes Servlets and the fly likes not able  get a string output Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply 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: 12266
    
    1
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


Java Resources at www.wbrogden.com
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: 56168
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56168
    
  13

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: 32611
    
    4
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: 12266
    
    1

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
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: not able get a string output
 
Similar Threads
How to invoke 'exe' in JSP
Keep getting NullPointerException
Tell me about exec(),biojava...,how to connect database written in c executable file?
how to send a string to a servlet from a java program
Use a javaBean in a jsp