2011-01-24 3 views
2

알아낼 수없는 세 가지 질문.Java에서 CommandLine 셸 만들기 : Begginner help

1) processbuilder를 사용하여 cat : C : \ xxx \ xxx.java 파일을 실행하는 새 프로세스를 만들고 싶습니다.하지만 Java 파일을 실행할 수는 없습니다. 나는 "분명히"와 "종료"를 각각 입력 할 때 나는 clearscreen하거나 창을 종료하는 방법을 알아낼 수 없습니다)

3를 컴파일하는 동안

2) 내 배열에 오류를 얻을. system.exit (O)는 가상 시스템을 종료하고 실제로는 창을 닫지 않는 것처럼 보입니다.

여기 내 코드가 있습니다. 유감스럽게 생각해서 미안하지만이 작업을 수행해야하며 요청할 사람이 없습니다.

import java.io.*; 

public class SimpleShell 
{ 

    public class JavaStringHistory 
     { 
      private String[] history = new String[4]; 
     } 

    public static void main(String[] args) throws 
      java.io.IOException { 

     String commandLine; 
     BufferedReader console = new BufferedReader 
      (new InputStreamReader(System.in)); 



      //Break with Ctrl+C 
      while (true) { 
      //read the command 
      System.out.print("shell>"); 
      commandLine = console.readLine(); 

      //if just a return, loop 
      if (commandLine.equals("")) 
      continue; 
      //history 
      if(commandLine.equals('*')) 
      { 
       //new class HistoryStringArray(); 
      // { 
       // history[4] = history[3] 
       // history[3] = history[2] 
       // history[2] = history[1] 
       // history[1] = history[0] 
       // history[0] = commandLine 
       } 
      //help command 
      if (commandLine.equals("help")) 
      { 
       System.out.println(); 
       System.out.println(); 
       System.out.println("Welcome to the shell"); 
       System.out.println("Written by: Brett Salmiery"); 
       System.out.println("CIS 390 - Dr. Guzide"); 
       System.out.println("--------------------"); 
       System.out.println(); 
       System.out.println("Commands to use:"); 
       System.out.println("1) cat prog.java"); 
       System.out.println("2) exit"); 
       System.out.println("3) clear"); 
       System.out.println(); 
       System.out.println(); 
       System.out.println("---------------------"); 
       System.out.println(); 
      } 

      if (commandLine.equals("clear")) 
      { 

       if (int cls = 0; cls < 10; cls++) 
       { 
       System.out.print(); 
       } 


      } 

      if (commandLine.endsWith(".java")) 
      { 
       if(commandLine.startsWith("cat")) 
       { 
       System.out.println("test"); 
       ProcessBuilder pb = new ProcessBuilder(); 
       //pb = new ProcessBuilder(commandLine); 
       } 

       else 
       { 
        System.out.println("Incorrect Command"); 
       } 
      } 

      if (commandLine.equals("exit")) 
      { 

       System.out.println("...Terminating the Virtual Machine"); 
       System.out.println("...Done"); 
       System.out.println("Please Close manually with Options > Close"); 
       System.exit(0); 
      } 




     } 
    } 
} 
+0

이 모든 것을 순수 자바로 작성해야합니까 ?? 화면을 지우는 순수 자바 방식 (적어도 Windows 환경에서는)이 없기 때문에. 그러나 JNI를 사용할 수 있다면 그렇게 할 수 있습니다. – Favonius

답변

1
  if (int cls = 0; cls < 10; cls++) 

난 당신이 역사 메커니즘에 관해서는 for :

을 의미 생각 : 당신은 하나의 개인 회원 (나쁜 시작)가있는 클래스 JavaStringHistory있어 히스토리에 항목을 추가하거나 히스토리에서 항목을 검색하는 메소드는 없습니다. 그래서 당신은 그 방법을 써야합니다. (주석 처리 된 코드가 시도한대로 멤버를 공개하고 저장할 수도 있지만 이미 클래스를 가지고 있기 때문에 추상화를 마칠 수 있습니다.)

ProcessBuilder , 나는 그것이 어떻게 작동하는지 전혀 모른다. 당신이 그걸로 무엇을하고 싶은지 잘 모르겠지만, FileReader 클래스를 사용하면 열거 된 소스 파일을 읽고 그것을 터미널에 출력 할 수 있습니다. (String.split 메서드를 사용하여 입력 문자열을 분리하고 각 부분을 개별적으로 살펴볼 수도 있습니다.)

터미널 창을 닫으시겠습니까? 오류. 거기에서 생각 나지 마라. 대부분의 전문가들은 때로는 바보 같은 일이 특정 환경에서 발생한다는 사실을 기꺼이 인식하고 있습니다.

호프가 도움이되기를 바랍니다.

+0

롤 예 durr을 의미했습니다 빠른 응답 감사합니다. 이것은 가장 도전적으로 도움이 될 것입니다. – Brett

관련 문제