0
public class Main
{
public static void main(String[] args) throws IOException
{

Process p = Runtime.getRuntime().exec("bash");
DataInputStream dis = new 
DataInputStream(p.getInputStream());
DataOutputStream dos = new 
DataOutputStream(p.getOutputStream());
//BufferedInputStream bis = new 
BufferedInputStream(p.getInputStream());

InputStream is = p.getInputStream();

dos.writeBytes("ps\n");
dos.flush();

int n;
while((n=is.read())!=-1){
System.out.print((char)n);
}
System.out.println("END");


}
}
3
  • уже все варианты перепробовал никак не получается выйти из цикла
    – Detaie Mac
    1 апр 2020 в 18:58
  • нашёл решение, надо было в цикле закрыть поток
    – Detaie Mac
    1 апр 2020 в 20:08
  • ещё нашёл вариант выхода из цикла не закрывая поток if(dos.size()<=3){break;}
    – Detaie Mac
    1 апр 2020 в 20:26

1 ответ 1

0
while((n=is.read())!=-1){
System.out.print((char)n);
dos.close();
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.