以 root 身份执行外部应用程序 - 问题

发布于 2024-10-14 23:57:22 字数 704 浏览 1 评论 0原文

早上好:

我正在尝试运行需要执行的外部应用程序 作为根。我必须在执行后读取 exit 中的行 该应用程序的但它说“权限被拒绝”,就好像 它没有正确完成。我思考了一段时间 我无法前进。代码如下:

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 );
   }
}
catch (IOException ioe)
{
  ioe.printStackTrace();
}
process.waitFor();

有谁知道为什么不让我运行命令?

谢谢。

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 );
   }
}
catch (IOException ioe)
{
  ioe.printStackTrace();
}
process.waitFor();

Does anyone know why not let me run the command?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福还没到 2024-10-21 23:57:22

尝试运行 su 时遇到任何错误吗? 会的,因为 su 可能会直接打开终端来提示输入密码;su 不会只读取密码的标准输入。)

(我想你 尝试运行简单程序(例如/usr/bin/cat /etc/passwd)时出现任何错误或成功吗?不妨先从简单的开始,看看是否可以让它工作,然后再尝试更复杂的程序。

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.

长安忆 2024-10-21 23:57:22

尝试

sudo -iu root

而不是 su怎么样?

what about trying

sudo -iu root

instead of su

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文