lamwaiman1988
lamwaiman1988

Reputation: 3742

Can we call a Windows cmd command in Java?

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

Answers (3)

Nirmal- thInk beYond
Nirmal- thInk beYond

Reputation: 12064

yes you can do it,USE

**Runtime.getRuntime().exec("your command");**

Upvotes: 2

Jon7
Jon7

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

BalusC
BalusC

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

Related Questions