Estou usando o seguinte codigo para formatar um disquete.
Mas logo depois q entro com o comando format a: ele encerra o programa e ñ me retorna nem formata o disquete alguem poderia me dar uma ajudinha[code]
public ArrayList ComandoShell(String comando ){
ArrayList<String> Mensagens = new ArrayList();
try{
boolean flag = true;
Process processo = Runtime.getRuntime().exec("cmd /c " + comando);
DataOutputStream output = new DataOutputStream(processo.getOutputStream());
BufferedReader input = new BufferedReader(new InputStreamReader(processo.getInputStream()));
BufferedReader erros = new BufferedReader(new InputStreamReader(processo.getErrorStream()));
String linha = new String();
do{
linha = input.readLine() ;
Mensagens.add(linha);
if(erros.ready())
{
Mensagens.add(erros.readLine());
}
try{
Thread.sleep(100);
}catch(InterruptedException ie){
System.out.println("Erro na InterruptedException");
}
}while((linha == null) && (erros.readLine() != null));
output.flush();
output.close();
input.close();
}catch(IOException ioe){
ioe.printStackTrace();
//return null;
}
return Mensagens;
}[/code]
E aew cara fiz algumas correções no seu código… só n fiz o teste com o comando FORMAT pq n tenho disquetes aqui…
Pode ser que o erro seja na Sixtaxe do comando format acesse o HELP dele FORMAT /? no prompt de comandos
[code]public class TesteDOS {
public static void main(String[] args) {
System.out.println("Aguarde...");
ArrayList<String> Mensagens = comandoShell("systeminfo");
for (String msg : Mensagens) {
System.out.println(" >>> " + msg);
}
}
public static ArrayList<String> comandoShell(String comando) {
ArrayList<String> mensagens = new ArrayList<String>();
try {
Process processo = Runtime.getRuntime().exec("cmd /c " + comando);
DataOutputStream output = new DataOutputStream(processo.getOutputStream());
BufferedReader input = new BufferedReader(new InputStreamReader(processo.getInputStream()));
BufferedReader erros = new BufferedReader(new InputStreamReader(processo.getErrorStream()));
String linha = new String();
do {
if (erros.ready()) {
linha = erros.readLine();
}else {
linha = input.readLine();
}
if(linha != null)
mensagens.add(linha);
} while (linha != null);
output.flush();
output.close();
input.close();
} catch (IOException ioe) {
ioe.printStackTrace();
// return null;
}
return mensagens;
}
}[/code]
Pode ser q não de certo pq quado vc executa o FORMAT ele pede para vc teclar enter para confirmar… vc teria que simular isso.
Eu tenho amenor ideia como se faz…
flw
[quote=RicardoCobain]E aew cara fiz algumas correções no seu código… só n fiz o teste com o comando FORMAT pq n tenho disquetes aqui…
Pode ser que o erro seja na Sixtaxe do comando format acesse o HELP dele FORMAT /? no prompt de comandos
[code]public class TesteDOS {
public static void main(String[] args) {
System.out.println("Aguarde...");
ArrayList<String> Mensagens = comandoShell("systeminfo");
for (String msg : Mensagens) {
System.out.println(" >>> " + msg);
}
}
public static ArrayList<String> comandoShell(String comando) {
ArrayList<String> mensagens = new ArrayList<String>();
try {
Process processo = Runtime.getRuntime().exec("cmd /c " + comando);
DataOutputStream output = new DataOutputStream(processo.getOutputStream());
BufferedReader input = new BufferedReader(new InputStreamReader(processo.getInputStream()));
BufferedReader erros = new BufferedReader(new InputStreamReader(processo.getErrorStream()));
String linha = new String();
do {
if (erros.ready()) {
linha = erros.readLine();
}else {
linha = input.readLine();
}
if(linha != null)
mensagens.add(linha);
} while (linha != null);
output.flush();
output.close();
input.close();
} catch (IOException ioe) {
ioe.printStackTrace();
// return null;
}
return mensagens;
}
}[/code]
Pode ser q não de certo pq quado vc executa o FORMAT ele pede para vc teclar enter para confirmar… vc teria que simular isso.
Eu tenho amenor ideia como se faz…
flw
[/quote]
Valeu kra. Vou fazer o teste qualquer coisa eu posto ai.