简体   繁体   中英

How to execute command prompt command through java

I am trying to download zip file from svn using java but nothing worked out. Through command prompt it is getting downloaded so i thought of executing command prompt through java . My java code is:

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();   

}
} 

The command which i am passing as an argument is executing through terminal but not getting executed through java code. Can anyone help me out.

To execute a command in Java:

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

For references: How do I run a batch file from my Java Application?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM