如何通过java执行命令提示符命令

时间:2015-04-10 09:34:02

标签: java

我正在尝试使用java从svn下载zip文件,但没有任何结果。 通过命令提示符,它会被下载,所以我想通过java执行命令提示符。 我的java代码是:

import java.io.BufferedReader;
import java.io.IOException;

import java.io.InputStreamReader;

public class aaa {

public static void main(String[] args) throws IOException, InterruptedException {

    String command = "svn co --username username --password pass http://interactive/svn/Test_Mariza/trunk/test/seatapps.zip /home/vaishali/aaa/";

    Process proc = Runtime.getRuntime().exec(command);

    // Read the output

    BufferedReader reader =  
          new BufferedReader(new InputStreamReader(proc.getInputStream()));

    String line = "";
    while((line = reader.readLine()) != null) {
        System.out.print(line + "\n");
    }

    proc.waitFor();   

}
} 

我作为参数传递的命令是通过终端执行但不通过java代码执行。 谁能帮我吗。

1 个答案:

答案 0 :(得分:-2)

在Java中执行命令:

Runtime.getRuntime().exec(" Insert command here ");

供参考: How do I run a batch file from my Java Application?