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

How to execute a cmd file from the java code?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to read the input and outputstreams of a process?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 80128
417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This same topic was discussed recently here.
 
It's never done THAT before. Explain it to me tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic