我正在处理的程序在主机线程旁边运行的线程中运行时从控制台拉出(检查扫描仪在读取之前是否有下一行),有一点我需要启动一个子进程还需要从控制台读取。我有一个类用于运行命令并获取其输出并从父进程的控制台将输入传递给它们。这在从Eclipse运行时工作正常,但如果我将它放入jar文件并从Windows控制台运行它我会收到此错误:
java.io.IOException: Not enough storage is available to process this command
java.io.FileInputStream.readBytes(Native Method),
java.io.FileInputStream.read(Unknown Source),
java.io.BufferedInputStream.read1(Unknown Source),
java.io.BufferedInputStream.read(Unknown Source),
bin.Exec_assist.run(Exec.java:172),
java.lang.Thread.run(Unknown Source)
一旦我按下输入就会发生此错误,无论我按哪个其他按键,控制台也不会让我输入任何内容。这是将控制台输入传递到子流程的代码片段:
public void run(){
byte[] b = new byte[8064 * 8];
int r;
is = System.in;
try{
while(run.isAlive()){//run is a pointer to an object passed in though the constructor, the object it points to is from a class that I use to determine if the process is still running
if(is.available() > 0){
r = is.read(b, 0, b.length);
os.write(b, 0, r);//os is the output stream for the process being run, also passed in through the constructor
os.flush();
}else{
Thread.sleep(500);
}
}
}catch(Exception e){
e.printStackTrace()
}
}
我已经尝试过转入扫描仪并在其上使用hasNext()但这只会导致新问题并且无法修复旧问题,它确实允许我输入Windows控制台但按Enter键仍会导致同样的错误。