| 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
|
|
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
|
|
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
|
|
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
|
|
|
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
|
|
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
|
|
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
|
 |
 |
|
|
subject: not able get a string output
|
|
|