sitelink1  
sitelink2  
sitelink3  

커맨드 명령어를 실행하는 함수

 

 

 

    private void executeCommand(String[] command) throws IOException, InterruptedException {

 

        System.out.println("명령어>>");

        for (int i = 0; i < command.length; i++) {

            System.out.print(command[i]);

        }

        System.out.println();

 

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

 

        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(), "ms949"));

        String line = null;

        StringBuffer lineSb = new StringBuffer();

        while ((line = br.readLine()) != null) {

            lineSb.append(line);

        }

 

        if (lineSb.length() > 0) {

            System.out.println(lineSb); // 실행 결과를 출력

        }

 

        lineSb = null;

        line = null;

        br.close();

        br = null;

 

        if (!p.waitFor(3, TimeUnit.SECONDS)) {

            System.out.println("Destroy");

            p.destroy();

        }

 

        command = null;

        p = null;

    }

 

 

 

커맨드 실행함수를 콜하는 코드

 

 

 

String[] command = new String[] {

            "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\tf.exe\" workfold \""+branch+"\" /unmap /collection:\"https://[tfs도메인]:[tfs포트]/tfs/[팀프로젝트]/\" /workspace:\"[workspace이름]\" /login:\"[아이디,비번]\"" };

this.executeCommand(command);

 

command = new String[] {

            "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\tf.exe\" workfold \""+branch+"\" \"D:\\WORK\\\" /collection:\"https://[tfs도메인]:[tfs포트]/tfs/[팀프로젝트]/\" /workspace:\"[workspace이름]\" /login:\"[아이디,비번]\"" };

this.executeCommand(command);

 

command = new String[] {

            "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\tf.exe\" get \"D:\\WORK\\\" /overwrite /force /recursive /version:C" + [변경집합] + " /login:\"[아이디,비번]\"" };

this.executeCommand(command);

 

 

 

프로그램을 실행하려는 PC의 작업영역을 손봐야 한다