Reputation: 3742
Can we call a Windows cmd command in Java? For example, calling the "unzip" command of Windows in a Java program. Would that be difficult?
Upvotes: 1
Views: 1464
Reputation: 12064
yes you can do it,USE
**Runtime.getRuntime().exec("your command");**
Upvotes: 2
Reputation: 7225
I would suggest using the newer class ProcessBuilder: http://download.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.html
It holds your hand a little bit more and it allows you to merge the error and stdout streams so that you don't have to have two streamgobbler threads running.
Upvotes: 1
Reputation: 1109422
Yes, that's possible. The most basic API which Java SE provides for this is the Runtime#exec()
. It has some known traps though, this article is an excellent read: When Runtime.exec() won't.
Note that Java SE provides the java.util.zip
package as well for zipping/unzipping files programmatically. See also this article for a guide.
Upvotes: 6