• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Facing weired behaviour using Runtime.getRuntime().exec

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I want to do the followings :-

1. I want to run a batch(.bat) file with some parameter using Runtime.getRuntime().exec command.
2. As soon as the above batch will be called the current page will be forwarded to another page.

Problem I am facing:-

i) When I am using the below code the batch is running but not in a separate process because after the Runtime.getRuntime
().exec is called untill the batch processing ends the jsp page is NOT getting forwarded to another jsp page.So it is taking longer time to forward to next page. I want it to be immediately forwarded to next page.



ii) Now If I run the below code removing the getErrorStream() snippet the batch is not getting called.



Note:- All the code is within try-catch block.

Please help.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you're following all advice given in this article.
 
Kousik Majumder
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I have gone through that article but did not find any probable solution.
 
Sheriff
Posts: 22783
131
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
The problem is that the JSP page is only considered to be ready when all of its output is done. In other words, only after the process is ready.

What you actually need is Ajax or a similar technique. You don't include the process' results directly into the JSP; instead you run it in the background, putting it into some queue. The Ajax code then queries this queue, returning the current contents, and with JavaScript you add it to the HTML page.

That makes it sound easy, but unfortunately it isn't. The Ajax code will not be that hard (that is, once you know how Ajax works); that will be handling the queue. Since the process is running in a background I don't know if you can have access to the user's session, which would be the best place to store this queue.

I'm going to move this to our JSP forum where people with more JSP experience may be able to give you some more hints.
 
Kousik Majumder
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,

Actually I am not bothered about the process's result , what I am bothered is to start the process in a new thread so that the jsp page do not wait for the process to end.
After calling the cmd.bat file the jsp file should continue with the rest of the page.
 
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
If this was my problem I would create a Runnable class that handles the complete submission of the exec command and saving the result. Create an instance, save the reference in session, start a new Thread to run it and finish the jsp page in the request Thread.

Bill
reply
    Bookmark Topic Watch Topic
  • New Topic