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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| public void ExecuteScript2()
{
System.out.println("je suis " + Thread.currentThread().getName());
String[] cmd = { "script/bin/sh.exe", "script/script.sh" };
//System.out.println("je suis "+Thread.currentThread().getName());
try
{
// final Process p = Runtime.getRuntime().exec("script/go.bat");
final Process p = Runtime.getRuntime().exec(cmd);
// Consommation de la sortie standard de l'application externe dans un Thread separe
new Thread() {
public void run() {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
try {
try {
while ((line = reader.readLine()) != null) {
System.out.println("OUT:" + line);
}
} catch (IOException ex) {
Logger.getLogger(Snippet.class.getName()).log(Level.SEVERE, null, ex);
}
} finally {
reader.close();
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}.start();
// Consommation de la sortie d'erreur de l'application externe dans un Thread separe
new Thread() {
public void run() {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line = "";
try {
while((line = reader.readLine()) != null) {
System.out.println("ERR:"+line);
}
} finally {
reader.close();
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}.start();
System.err.println("Waiting");
p.waitFor();
System.err.println("Fini");
} catch (Exception e)
{
e.printStackTrace();
}
}
public void ExecuteTachFond(){
int DAY_LENGTH = 1000 * 60 * 60 * 24;
DAY_LENGTH = 20000;
Date now = new GregorianCalendar(Locale.getDefault()).getTime();
Date tomorrow = new Date((now.getTime()/DAY_LENGTH + 1) * DAY_LENGTH);
Timer tempsTimer = new Timer("Planificateur", false);
// final ExecuteScript toto = new ExecuteScript();
TimerTask timerTache = new TimerTask() {
public void run() {
System.out.println("Lancement");
//System.out.println();
ExecuteScript2();
}
};
tempsTimer.schedule(timerTache, now, DAY_LENGTH);
}
public static void main(String[] args) {
Snippet e =new Snippet();
e.ExecuteTachFond();
// e.ExecuteScript2();
}
} |
Partager