Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Runtime.getRuntime().exec() not working in tomcat  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Iam developing one spring boot application. I need to execute batch file for one process.

when i try to execute in eclipse. it is working. but i create a war and deploy into the tomcat. its not working.

What is the issue? anything i need to add before execution of Runtime.getRuntime().exec("daily.bat"); ?


Please clarify.


Thanks.
Vinoth
 
Sheriff
Posts: 24291
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vinoth sathi wrote:What is the issue?


That's a good question. I would suggest you start by finding out. Are there no logs? Are you not examining the output from syserr when you run that command?

There could be all kinds of things wrong. One thing I notice right away is that you're executing a command in the current working directory. Tomcat's current working directory is unlikely to be the place where you stored your daily.bat file. But there could be a lot of other issues to deal with besides that.
 
Saloon Keeper
Posts: 9996
208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the batch file comes with your application and doesn't need to be changed, you can package it in your WAR and access it through Class.getResourceAsStream(). Make sure to read the documentation well, because many people make the wrong assumptions about the method's argument.
 
vinoth sathi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have checked my code. Runtime.getRuntime().exec("daily.bat"); is calling

but not executing inside task.

Inside daily.bat has

wscript D:\daily.vbs


Its not calling wscript.exe

anything blocked to call wscript from tomcat ?

Please assist.
 
Rancher
Posts: 3986
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it giving an error?
Are you checking the error and output streams?

That should tell you what's happening.
 
vinoth sathi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Its not giving any error. simply waiting for long time to get the response from wscript. Is there any way to check ?
 
Marshal
Posts: 63822
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We need more details before we can help. How much experience have you got with Runtime.exec()? How are you emptying its input and error streams? Why aen't you using a process builder object?
 
Dave Tolls
Rancher
Posts: 3986
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vinoth sathi wrote:Hi,

Its not giving any error. simply waiting for long time to get the response from wscript. Is there any way to check ?



So, what do the two streams show you?
 
vinoth sathi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I have tried with ProcessBuilder class to check.

List<String> args1 = new ArrayList<String>();
 args1.add ("D:\\test.bat"); // command name
 ProcessBuilder pb = new ProcessBuilder (args1);
 Process p = pb.start();
         System.out.println("starting");
 p.waitFor();
System.out.println("started");

After pb.start() no response. not getting p.waitfor() method response.


Later i checked is there any blockage and found "Interactive services detection " is blocking. how to resolve this?

I checked with sys admin. no blockage.
 
Dave Tolls
Rancher
Posts: 3986
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Process has two input streams, one covering the normal output stream of the proces being run, and one for the error stream.
You need to be reading from these and output the result so you can see what the process is doing.
 
Campbell Ritchie
Marshal
Posts: 63822
209
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We shall have to bring out Michael Daconta: see the three links in this old post. Don't go anywhere near processes or process builder until you have understood Daconta's article.
 
Sheriff
Posts: 21692
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still a great article, but it could use an update. For instance, if you use a ProcessBuilder and redirect the error stream to the output stream, you don't need any additional threads - you can simply read everything from the resulting Process' getInputStream() before you call waitFor (which is then the same as exitValue).
 
vinoth sathi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

After tried all. I used to start the Tomcat service (tomcat.exe) instead of tomcatw.exe gui tool to start. After that wscript.exe was getting called. Still wonder why this was not working with tomcat gui service.
Is there any log on to use full administrative account to access system files?

Any idea?
 
See where your hand is? Not there. It's next to this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!