자바에서 외부파일을 실행시키거나, cmd 명령을 위해서 Runtime객체를 사용한다.

 

확장자가 .exe로 끝나는 외부파일을 실행시킬때에는

try {
      Process process = Runtime.getRuntime().exec("c:/windows/notepad.exe");     
     } catch (IOException e1) {
      System.out.println(e1);
     }

로 실행시키면된다.

 

하지만 .exe로 끝나는 파일이 아니면 (예:.mov)

try {
Process process = Runtime.getRuntime().exec("cmd -c d:/test/test.mov");
} catch (IOException e1) {
System.out.println(e1);
}

로 실행시켜 줘야한다.

======================================================================

여기에서 process는 cmd창의 Stream을 얻어온다.

cmd창 실행 후 계속 할일이 있다면 process를 이용하면 된다.

 

[참고함] http://day0429.tistory.com/entry/Runtime-%EA%B0%9D%EC%B2%B4-cmd%EB%AA%85%EB%A0%B9

 

그런데 window8 에서 명령이 실행이 안된다. 관리자 권한으로 실행하는 방법 확인이 필요함

이 부분을 확인하기 위하여 좀더 체크가 필요함.

자바에서 Runtime.getRuntime().exec() 를 사용하여 windows 명령어를 실행하는 방법.

여기서 command는 실행 명령어 이다.

예 : move c:\data\source.txt c:\data\target.txt  <- 윈도우용

예 : mv /data/source.txt /data/target.txt <- 리눅스용


Process process;
String osName = System.getProperty("os.name");
String[] cmd;

if(osName.toLowerCase().startsWith("window")) {
    cmd = new String[] { "cmd.exe", "/y", "/c", command };
} else {
    cmd = new String[] { "/bin/sh", "-c", command };
}

process = Runtime.getRuntime().exec(cmd);

return process.waitFor();

[출처] http://blog.daum.net/lkflower/17224498  참고함.

OS 테스트 하기 위한 예제 소스

public class OS_Test {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  String osArchitecture = System.getProperty("os.arch");
  String osName = System.getProperty("os.name");
  String javaHome = System.getProperty("java.home");
  String currentDirectory = System.getProperty("user.dir");
  String userHome = System.getProperty("user.home");
  // 32비트 인지 64비트인지 구별하기 위해 추가함
  String archDataModel = System.getProperty("sun.arch.data.model");
  
  System.out.println(osArchitecture);
  System.out.println(osName);
  System.out.println(javaHome);
  System.out.println(currentDirectory);
  System.out.println(userHome);
  System.out.println(archDataModel);
 }

}

 

 

오라클 no wait 에 걸렸을때 확인방법

SELECT A.SID, A.SERIAL#, B.TYPE, C.OBJECT_NAME
FROM V$SESSION A, V$LOCK B, DBA_OBJECTS C
WHERE A.SID=B.SID
AND B.ID1=C.OBJECT_ID
AND B.TYPE='TM'

오라클 no wait 에 걸린넘 죽일 때

ALTER SYSTEM KILL SESSION 'SID, SERIAL#';

+ Recent posts