이 코드에서 .sh 파일을 루트로 실행하는 방법은 무엇입니까? 메인 섹션의 은 내 .sh 파일을 원하는 디렉토리에서 실행합니다. 하지만 내가 달릴 때 허락을받지 못했습니다. 간단하게 .sh 코드를 루트로 실행하고 싶습니다. 어떤 방법이 있습니까? 자바 코드에서 쉘 스크립트를 루트로 실행
import java.io.IOException;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
public class TestScript {
int iExitValue;
String sCommandString;
public void runScript(String command){
sCommandString = command;
CommandLine oCmdLine = CommandLine.parse(sCommandString);
DefaultExecutor oDefaultExecutor = new DefaultExecutor();
oDefaultExecutor.setExitValue(0);
try {
iExitValue = oDefaultExecutor.execute(oCmdLine);
} catch (ExecuteException e) {
// TODO Auto-generated catch block
System.err.println("Execution failed.");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println("permission denied.");
e.printStackTrace();
}
}
public static void main(String args[]){
TestScript testScript = new TestScript();
testScript.runScript("sh /home/deepak/Desktop/ftpusers.sh");
}
}
netbeans를 사용하고 있습니다. 지금 구현하는 방법은 무엇입니까? 제발 도와주세요 –
@ DeepakKr.Karn는 다음과 같이 시도합니다 : _testScript.runScript ("gksudo sh /home/deepak/Desktop/ftpusers.sh");_ – bedrin
나는 .. .. –