一般来说,用Process执行后都是这么输出的:
process = Runtime.getRuntime().exec("python.exe " this.tempFile);
in = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
StringBuffer outputBuffer = new StringBuffer(); while ((s = in.readLine()) != null) { outputBuffer.append(s); }
当执行到输入语句,例如
i=input("请输入xxx")
那么这个"请输入xxx"一般都会在用户输入后才能显示,那怎么才能用户输入前就显示呢?否则还有什么意义?
遇到input,要这么取输出:
// 获取输入提示 StringBuilder stringBuilder = new StringBuilder(); int currentChar; while ((currentChar = br.read()) != -1) { char c = (char) currentChar; if (currentChar == 32) { //遇到空格在网页里会被忽略,可以替换成 c=" "; stringBuilder.append(c); }else
stringBuilder.append(c); System.out.print(c); } String result = stringBuilder.toString();
一行一行取会阻塞,一个一个取就能取到这个提示了