Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to execute a cmd file from the java code?  RSS feed

 
navat venu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to execute a cmd file from the java code?

Actually i have to restart the weblogic server, when i click a button
on my jsp page.
So, I wanted to execute stopWeblogic.cmd and startWeblogic.cmd from the code.

How to do this?
 
Kaleeswaran Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by navat venu:
How to execute a cmd file from the java code?

Actually i have to restart the weblogic server, when i click a button
on my jsp page.
So, I wanted to execute stopWeblogic.cmd and startWeblogic.cmd from the code.

How to do this?


try{
Process process1 = Runtime.getRuntime().exec("\\directoryPath \\stopWeblogic.cmd");
}catch(Exception e){};
 
navat venu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried running this code,

try{
Process process1 = Runtime.getRuntime().exec("C:\\bea\\user_projects\\domains\\base_domain\\startweblogic.cmd");
}catch(Exception e){};

Its not starting the server though it is not giving any errors.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
}catch(Exception e){};

How do you know there are no errors if you suppress all exceptions?

How are you handling the input and output streams of the child process?
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you read from both the input and error streams from a process, you risk freezing the process because its buffers are full.
 
navat venu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to read the input and outputstreams of a process?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in This article talks about what you need to watch out for when using Runtime.exec, especially the handling of the I/O streams.

I could imagine there being problems with this approach, since you're trying to kill the server that executes the command. That's just a hunch, though.
 
Campbell Ritchie
Marshal
Posts: 55735
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This same topic was discussed recently here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!