2011-11-19 3 views
0

버튼이 하나 뿐인 작은 앱이 있습니다. 버튼을 눌렀을 때 프로세스가 실행 중인지 확인하고 싶습니다. 그것은 그것이 아니라면 x를합니다.프로세스가 실행중인 경우 수행해야합니다. 그렇지 않으면

이것은 지금까지 저의 겸손한 코드입니다. 단추와 클릭 만 포함된다는 것을 알고 있습니다. 나는이 책에서 정말로 비어 있습니다.

public class toggle { 
    public static void main(String[] args) { 
     Display myDisplay = new Display(); 
     Shell myShell = new Shell(myDisplay); 
     myShell.setText("uTorrent Toggle"); 
     myShell.setBounds(120, 120, 220, 120); 
     myShell.setLayout(new FillLayout()); 
     final Button Start = new Button(myShell, SWT.PUSH); 
     Start.setText("Start uTorrent"); 
     Start.addSelectionListener(new SelectionAdapter() { 
     public void widgetSelected(SelectionEvent event) { 
      Start.setText("Kill uTorrent"); 
      try { 
       Runtime.getRuntime().exec("/bin/bash -c \"utorrent start\""); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
     }); 
     myShell.open(); 
     while (!myShell.isDisposed()) { 
     if (!myDisplay.readAndDispatch()) myDisplay.sleep(); 
     } 
     myDisplay.dispose(); 
} 
} 

답변

0

프로세스가 실행 중인지 확인하려면 필요에 따라 "ps -efw"출력을 사용하거나 다른 인수를 사용할 수 있습니다.

관련 문제