Java与bash程序交互出问题

来源:互联网 发布:客厅改装 知乎 编辑:程序博客网 时间:2024/06/01 07:37
今天试了一下,发现在调用dos,bash的程序时,不能很好的获得输出流。

public class MainEntry {

    
/**
     * 
@param args
     
*/

    
public static void main(String[] args) {
        
        
try {
            Process installProcess 
= Runtime.getRuntime().exec("./install.bin -console | tee install.log");
            
            InputStream inputStream 
= installProcess.getInputStream();
            BufferedReader inputBuffer 
= new BufferedReader(new InputStreamReader(inputStream));
            
            
while (true )
            
{
                
boolean isInputReady = inputBuffer.ready();
                
if (isInputReady == false)
                
{
                    Thread.sleep(
5000);
                    System.out.println(
"No Input");
                    
continue;
                }

                String inputLine 
= inputBuffer.readLine();
                
while(inputLine != null || inputLine != "")
                
{
                    System.out.println(inputLine);
                    Thread.sleep(
2000);
                }

            }

            
            
        
        }
 catch (Exception e) {
        
            e.printStackTrace();
        }


    }


}
原创粉丝点击