• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Get grep output in JSP

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

Could someone please help me with how to get Unix command output in my JSP file? I am able to execute a unix command from JSP. However, I need to display the output in my JSP and I am not able to do it. This is what I am doing in my JSP -



Thanks in advance!
 
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When exec()ing, you MUST consume the stdOut and stdErr streams created by the process.

If you don't the process will probably hang indefinately.

The JavaDocs for java.lang.Process should have been your first stop when researching this question.

See also the classic artice on exec() here.

Bill
 
Bear Bibeault
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since this is much more about exec() and not so much about JSP, moved to a more appropriate forum.
 
Jd Steven
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out.

 
Sheriff
Posts: 22208
117
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not going to work. The p.waitFor() call will block until you clear out the InputStream. You only start doing that afterwards though.
 
Jd Steven
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it does work fine. Thanks.
 
Rob Spoor
Sheriff
Posts: 22208
117
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider yourself lucky. Apparently your process' buffer has not been filled yet. If it writes more to its output stream the buffer will be filled, and because you do not clear it until after the call to waitFor() that call will then block indefinitely. Read the article William linked to, really.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, there are plenty of pitfalls here.

As Rob pointed out the fact that it worked once means only that you got lucky on the size of the Process output buffer. Also, if for some reason the process writes to the stdErr stream the program will likely hang indefinately.

Bill
 
Jd Steven
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the link to article. It was pretty good.

Bill, on process hanging for infinite time if it writes to stdErr, that doesn't happen. I tested it and all I had to do was instead of getting inputStream get errorStream to process error response. So one block for input stream and one block for error stream.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So one block for input stream and one block for error stream.



I would swear that was exactly what I was trying to tell you - where did I go wrong?

For best result you need separate Threads to consume both stdOut and stdErr streams just in case a more complex process produces a mixture of both.

Bill
 
Danger, 10,000 volts, very electic .... tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic