Salve a tutti, come da titolo sto cercando di leggere l'output di un programma, la cosa mi riesci fin tanto che l'output è corto. Ho scritto questa classe
codice:
public class AdbManager{
private String _adbPath;
Process _p=null;
public AdbManager(String adbPath)
{
_adbPath=adbPath;
}
public void start(String arg)
{
try
{
_p = Runtime.getRuntime().exec(_adbPath + " " + arg);
}
catch (IOException e)
{
System.out.println("ERROR: I can't start adb\n"+e.toString());
System.exit(-1);
}
}
public String getOutput()
{
BufferedReader input = new BufferedReader(new InputStreamReader(_p.getInputStream()));
StringBuilder stroutput = new StringBuilder();
int c;
try
{
while((c=input.read()) >= 0)
{
stroutput.append((char)c);
}
}
catch (IOException e)
{
System.out.println("ERROR: I can't get adb output\n"+e.toString());
System.exit(-1);
}
return stroutput.toString();
}
}
Chiamo start passando una stringa con gli argomenti da passare all'eseguibile
poi chiamo la funzione getOutput per leggere cosa ha restituito l'eseguibile.
Se l'output è di poche righe riesco a leggerlo tranquillamente, se invece è più lungo input.read() torna -1 alla prima chiamata e non legge niente.
Qualcuno saprebbe aiutarmi? Grazie mille in anticipo
Andrea993