
Envoyé par
mavina
P.S. : pas d'exception levée, je viens d'ajouter des SOP

C'est pas beau les bloc catch vide 
En plus tu t'embêtes avec tes 3 try/catch !!! En intégrant le try/finally directement dans le try/catch c'est nettement plus lisible et tu as un seule gestion des exceptions :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public static void main(String[]args)
{
String s=null;
try
{
Process p = Runtime.getRuntime().exec(new String[]{"sh","-c","echo", "$ORACLE_HOME"});
p.getOutputStream().close();
p.getErrorStream().close();
InputStream i=p.getInputStream();
try {
s = toString(i);
} finally {
i.close();
}
p.waitFor();
} catch(Exception e) {
e.printStackTrace();
}
System.out.println(s);
} |
Sinon il est peut-être possible que sh -c attendent un seul paramètre, donc :
Runtime.getRuntime().exec(new String[]{"sh","-c","echo $ORACLE_HOME"});
(désolé je ne peux pas testé)
a++
Partager