Existe-t-il un moyen d'obtenir l'UID d'un utilisateur sur une machine Linux en utilisant Java ? Je suis au courant de System.getProperty("user.name");
mais elle renvoie le nom de l'utilisateur et je cherche l'UID.
Réponses
Trop de publicités?Vous pouvez exécuter id
et lire le résultat.
par exemple :
$ id -u jigar
sortie :
1000
vous pouvez exécuter la commande par
try {
String userName = System.getProperty("user.name");
String command = "id -u "+userName;
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
process((char)c);
}
in.close();
} catch (IOException e) {
}
Erik Martino
Points
793
Utilisateur non enregistré
Points
0
vz0
Points
11605
ShiDoiSi
Points
4585