Formatar disquete

2 respostas
Slipguedes
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
public ArrayList<String> 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;
    }

2 Respostas

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

public class TesteDOS {

	public static void main(String[] args) {
                System.out.println(&quot;Aguarde...&quot;);
		ArrayList&lt;String&gt; Mensagens = comandoShell(&quot;systeminfo&quot;);
		
		for (String msg : Mensagens) {
			System.out.println(&quot; &gt;&gt;&gt; &quot; + msg);
		}
	}

	public static ArrayList&lt;String&gt; comandoShell(String comando) {
		ArrayList&lt;String&gt; mensagens = new ArrayList&lt;String&gt;();
		
		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;
	}
}

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

Slipguedes
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
public class TesteDOS {

	public static void main(String[] args) {
                System.out.println(&quot;Aguarde...&quot;);
		ArrayList&lt;String&gt; Mensagens = comandoShell(&quot;systeminfo&quot;);
		
		for (String msg : Mensagens) {
			System.out.println(&quot; &gt;&gt;&gt; &quot; + msg);
		}
	}

	public static ArrayList&lt;String&gt; comandoShell(String comando) {
		ArrayList&lt;String&gt; mensagens = new ArrayList&lt;String&gt;();
		
		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;
	}
}

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


Valeu kra. Vou fazer o teste qualquer coisa eu posto ai.

Criado 7 de junho de 2008
Ultima resposta 9 de jun. de 2008
Respostas 2
Participantes 2