2014-03-28 6 views
0

원격 디버깅이 필요한 보안 시스템에서 작업하려고합니다. 내가 찾고있는 것은 아래 예제와 같이 String에있는 코드를 실행하는 방법입니다 하지만 자바와.자바 문자열에서 코드를 실행하는 방법

try { 

    String Code = "rundll32 powrprof.dll, SetSuspendState";// the code we need to excecute 

    Runtime.getRuntime().exec(Code); 


} catch (IOException e) { 
} 
+0

가능한 복제본 [백그라운드에서 Java 코드에서 명령 줄을 실행하는 방법은 무엇입니까?] (http://stackoverflow.com/questions/11394394/how-do-i-run-command-line-from-java- code-in-the-background) – logoff

+7

문자열의 이전 코드를 실행하는 것이 보안 시스템의 반대라고 생각했을 것입니다 ... – doctorlove

답변

1
String Code = "rundll32 powrprof.dll, SetSuspendState"; 

    StringBuffer output = new StringBuffer(); 

    Process p; 
    try { 
     p = Runtime.getRuntime().exec(Code); 
     p.waitFor(); 
     BufferedReader reader = 
         new BufferedReader(new InputStreamReader(p.getInputStream())); 

        String line = "";   
     while ((line = reader.readLine())!= null) { 
      output.append(line + "\n"); 
     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    System.out.println(output.toString()); 

자세한 내용은 다음 URL을 참조하십시오 당신은 정말 내가 정말 원하는 cmd를 codes.what을 실행하지 않으려는 틀렸다는 가지고 어떤 친구가 자바 명령을 실행할 수 없습니다 http://www.mkyong.com/java/how-to-execute-shell-command-from-java/

0

. 다음과 같이 전달되는 문자열입니다.

예 :

문자열 코드 = "에서 System.out.println ("테스트 코드 ")";

Runtime.getRuntime(). exec (Code);

이와 비슷한 내용입니다.

+0

질문에있는 예는 그렇지 않다는 것을 나타냅니다. 나는 진실을 말하기 위해 원래의 질문을 적용 할 것이다. – Gimby

관련 문제