|
J'ai un programme java qui doit cree un fichier script sous
Unix/Linux. ce fichier script est une commande qui permet de lancer un utilitaire Oracle : SQL*LOADER. J'arrive bien a executer une commande shell
ou un script shell de windows vers unix ou de unix vers unix mais je n'arrive
pas a executer une commande de windows vers windows ou d'unix vers windows. Pour
cela j'utilise jrexec qui permet d'envoyer des commandes d'un system a un autre.
Il est a l'ecoute du port 512. Et je suppose que sous windows, il n' y a pas de
serveur a l'ecoute de ce port comme sous unix donc il me faudrait creer un
serveur sur un poste windows pour que cela fonctionne. Mais, quand je fais un
programme qui utlise la classe Runtime pour envoyer une commande dir par exemple
sur mon propre poste windows, ca ne fonctionne pas. Pourquoi?
Ci dessous le programme
import java.lang.Runtime;
import java.lang.Process; import java.io.IOException; import java.lang.InterruptedException; class ExecCmd{
public static void main(String args[]){ System.out.println("IN MAIN"); String command = "C:\\temp\\essaiScript.bat "; // l'execution d'un script ne fonctionne pas String command = "C:\\Program
Files\\Microsoft Office\\Office\Winword.exe"; //
l'execution d'un exe fonctionne
Runtime runtime = Runtime.getRuntime(); Process process = null; try{ process = runtime.exec(command); /* try{ process.waitFor(); }catch(InterruptedException intexc){ System.out.println("Interrupted Exception on waitfor: " +intexc); }*/ System.out.println("Return code from process " + process.exitValue()); System.out.println("Done executing"); }catch(Exception e){ System.out.println("IO Exception from exec: "+e.getMessage()); e.printStackTrace(); } /* try{ Process p = Runtime.getRuntime().EXEC(args[0]); try{
p.waitFor(); }catch(InterruptedException intexc){ System.out.println("Interrupted Exception on waitfor: " +intexc); } System.out.println("commande " + args[0]); System.out.println("Return code from process " + p.exitValue()); System.out.println("Done executing"); }catch(IOException
e){
System.out.println("IO Exception from exec: "+e.getMessage()); e.printStackTrace(); }*/ }
} |
- RE: comment executer une commande windows a partir de java Fabien Lonardi
- RE: comment executer une commande windows a partir de ... Damien Lecan
- RE: comment executer une commande windows a partir... Fabien Lonardi
- RE: comment executer une commande windows a partir... Fabien Lonardi
- RE: comment executer une commande windows a pa... Damien Lecan
- RE: comment executer une commande windows ... Fabien Lonardi
- RE: comment executer une commande win... Damien Lecan
