如果挂起
readLine(),则意味着您的“
while”永远不会结束(考虑您的代码可能不太可能),或者
readLine()正在等待其“源”,即
IOstream线程原因造成的阻塞
available()!=true。
如果没有看到调试信息,我就无法对您的代码进行故障排除。但是作为建议,您尝试过
PipedIntputStream吗?这个想法是将控制台输入传递到“您的”输出,以便您可以“编写”它。为此,您需要初始化输入/输出。
InputStream in = new PipedInputStream();PipedOutputStream pin = new PipedOutputStream((PipedInputStream) in);channel.setInputStream(in);channel.connect();pin.write(myscript.getBytes());
您的问题(如何读取控制台输出)也是如此。
PipedInputStream pout = new PipedInputStream((PipedOutputStream) out);BufferedReader consoleOutput = new BufferedReader(new InputStreamReader(pout));consoleOutput.readLine();
再一次,如果您不确定要读取多少行并因此要使用“ while”,请确保在while内执行一些 *** 作,以防止1)忙等待2)结束条件。例:
while(!end){ consoleOutput.mark(32); if (consoleOutput.read()==0x03) end = true;//End of Text else { consoleOutput.reset(); consoleOutput.readLine(); end = false; }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)