Commande avec java au shell

CrazyDog_974 Messages postés 19 Date d'inscription jeudi 22 janvier 2004 Statut Membre Dernière intervention 28 avril 2005 - 22 janv. 2004 à 11:15
CrazyDog_974 Messages postés 19 Date d'inscription jeudi 22 janvier 2004 Statut Membre Dernière intervention 28 avril 2005 - 23 janv. 2004 à 13:02
j'ai quelque petits soucis alors je n'arrive pas à passe un cmd au shell pourtant :
 try{
       java.lang.Runtime run = java.lang.Runtime.getRuntime();
       String Cmd ="dir c:\";
       
       java.lang.Process P = run.exec(Cmd);
       
       InputStream F = P.getInputStream();
       System.out.println(F);
        }
        catch(IOException ex){            
             System.out.println(ex.getMessage() + " " );
            
        }
        catch(NullPointerException ex){            
             System.out.println(ex.getMessage() + " " );
            
        }

et il y a un erreur:
CreateProcess: dir c:\ error=2
qq1 peut m'aide
Le CrazyDog vous salut bien bas! :shy)

2 réponses

cs_neodante Messages postés 2835 Date d'inscription lundi 11 août 2003 Statut Modérateur Dernière intervention 16 décembre 2006 11
23 janv. 2004 à 10:12
:big) Neodante :big)

Voici un bout de la javadoc dans lequel tu trouveras certainement un moyen de savoir où se trouve ton erreur :

The Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. The class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.

The Runtime.exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

The subprocess is not killed when there are no more references to the Process object, but rather the subprocess continues executing asynchronously.

Voilà à mon avis regarde la méthode getErrorStream et regarde à quoi correspond la valeur 2 de retour par exemple en regardant dans les sources de la Process !
@+ ;)

[Responsable www.neogamedev.com]
0
CrazyDog_974 Messages postés 19 Date d'inscription jeudi 22 janvier 2004 Statut Membre Dernière intervention 28 avril 2005
23 janv. 2004 à 13:02
salut neodante, voila j'ai fait ce que tu m'as dit, je ne suis trop bon en anglais, mais je n'ai pas trouver http://java.sun.com/j2se/1.4.2/docs/api/index.html
de numero d'erreur et ca correspondance !!
Le CrazyDog vous salut bien bas! :shy)
0
Rejoignez-nous
A voir également