Sim...dê uma olhada na classe Runtime e Process...com elas vc não somente 
pode executar qualquer comando como chamar qualquer aplicação, além de pegar fluxos I/O.
 
Veja um exemplo:
 
import java.io.*;

public class Example {

public static void ExecuteCommand (String ExternCommand) throws IOException
{
Process proc = Runtime.getRuntime().exec("start command /c "+ExternComand+" >output.txt");
char c;
try { proc.waitFor(); }
catch (InterruptedException e) { System.out.println("InterruptedException raised: "+e.getMessage()); }
InputStream f = new FileInputStream ("output.txt");
while ((c=(char)f.read())!=(char)-1)
System.out.print(c);
}

public static void main (String args[]) throws IOException
{
String ExternCommand = new String();
int k;
for (k=0;k<args.length;k++) { if (k>0) ExternComand = ExternCommand + " ";
ExternCommand = ExternCommand + args[k];
}
try { System.out.println("Command: "+ExternCommand);
ExecuteCommand(ExternCommand);
}
catch (IOException e) { System.err.println ("IOException raised: "+e.getMessage()); }
}

}
 
[] 's
Rodrigo
----- Original Message -----
Sent: Thursday, December 20, 2001 1:05 PM
Subject: [java-list] shell no java

é possível fazer um shell de algum comando do sistema
operacional pelo java ?
 
por exemplo um dir do windows ...
 
grato,
 
 

Responder a