以 root 身份执行外部应用程序 - 问题
早上好:
我正在尝试运行需要执行的外部应用程序 作为根。我必须在执行后读取 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试运行
su
时遇到任何错误吗? 会的,因为su
可能会直接打开终端来提示输入密码;su
不会只读取密码的标准输入。)(我想你 尝试运行简单程序(例如
/usr/bin/cat /etc/passwd
)时出现任何错误或成功吗?不妨先从简单的开始,看看是否可以让它工作,然后再尝试更复杂的程序。Do you have any errors when trying to run
su
? (I imagine you would, sincesu
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.尝试
而不是 su怎么样?
what about trying
instead of su