开发者

Execute an external application as root - problem

Good morning:

I'm trying to run an external application that needs to be executed as root. I have to read the lines from exit after the execution of this application but it says "permission denied", as if the its not been done correctly. I've been thinking over a time and I can not move forward. The code is as follows:

process = Runtime.getRuntime().exec("su");
String[] command = {external application command};
process = Runtime.getRuntime().exec(comando);
InputStream inputStream = process.getInputStream();
BufferedReader bufferedReader = null;
try
{
   bufferedReader = new BufferedReader(new
       InputStreamReader(inputStream),8192);
   String line = null;
   while ((line = bufferedReader.readLine()) != null)
   {
      System.out.println("read line:"+line )开发者_C百科;
   }
}
catch (IOException ioe)
{
  ioe.printStackTrace();
}
process.waitFor();

Does anyone know why not let me run the command?

Thanks.


Do you have any errors when trying to run su? (I imagine you would, since su will probably open the terminal directly to prompt for a password; su won't just read standard input for a password.)

Do you have any errors or success when trying to run a simple program, like /usr/bin/cat /etc/passwd? Might as well start simple and see if you can get it to work before trying for more complicated programs.


what about trying

sudo -iu root

instead of su

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜