1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
String lResult;
String pFilePath = "fichier.txt";
String lFileName = new File(pFilePath).getName();
String lFileOut = "out" + lFileName + ".log";
String lCmd = "/usr/bin/cksum " + pFilePath + " > " + lFileOut;
try {
Runtime lRuntime = Runtime.getRuntime();
Process lProcess = lRuntime.exec(lCmd);
// attente de la fin d'execution de la commande si necessaire
lProcess.waitFor();
System.out.println(lCmd);
System.out.println(lProcess.exitValue());
BufferedReader lReader = new BufferedReader(new FileReader(lFileOut));
String lReturn = lReader.readLine();
lReader.close();
String[] lReturns = lReturn.split(" ");
if(lReturns.length == 3){
lResult = lReturns[0];
}
lResult = "Error1";
}catch(Exception e) {
e.printStackTrace();
lResult = "Error2";
}
System.out.println(lResult);
}
} |
Partager