• Post Reply Bookmark Topic Watch Topic
  • New Topic

Facing weired behaviour using Runtime.getRuntime().exec

 
Kousik Majumder
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • 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.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you're following all advice given in this article.
 
Kousik Majumder
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have gone through that article but did not find any probable solution.
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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: 239
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!