I need to execute the decode -t 17 through Java.But it requires root permission.So I thought of executing su -i to change to root and then execute the decode command.But nothing happens.Please help:
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textArea.setText("");
repaint();
try{
p = Runtime.getRuntime().exec("sudo -i");
p.waitFor();
p.destroy();
p = Runtime.getRuntime().exec("dmidecode –t 17");
BufferedReader br = new BufferedReader(
new InputStreamReader(p.getInputStream()));
while ((s = br.readLine()) != null)
textArea.setText(s);
p.waitFor();
p.destroy();
p = Runtime.getRuntime().exec("su - mayooran");
p.waitFor();
p.destroy();
}
catch(Exception e)
{
}
}
});
btnNewButton.setBounds(404, 89, 119, 34);
contentPane.add(btnNewButton);
You have many options:
1- You can write script that writes the static output of dmidecode to a world-readable file or you can use other information sources (e.g. /proc/meminfo ).
2- do the following on the shell:
chgrp $usergroup /usr/sbin/dmidecode
chmod g+s /usr/sbin/dmidecode