aspose file tools*
The moose likes Beginning Java and the fly likes How to execute a cmd file from the java code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to execute a cmd file from the java code?" Watch "How to execute a cmd file from the java code?" New topic
Author

How to execute a cmd file from the java code?

navat venu
Ranch Hand

Joined: May 14, 2006
Posts: 66
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?


-------------------- <br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD 5(in progress)<br /> <br />"Do, what you think that you cannot do"
Kaleeswaran Karuppasamy
Ranch Hand

Joined: Jul 19, 2007
Posts: 154
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){};


Judge a man by his questions rather than his answers --Voltaire
SCJP 1.5 97%
navat venu
Ranch Hand

Joined: May 14, 2006
Posts: 66
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
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
}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?


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Unless you read from both the input and error streams from a process, you risk freezing the process because its buffers are full.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
navat venu
Ranch Hand

Joined: May 14, 2006
Posts: 66
How to read the input and outputstreams of a process?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
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
Sheriff

Joined: Oct 13, 2005
Posts: 39867
    
  28
This same topic was discussed recently here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to execute a cmd file from the java code?