0

我正在处理的程序在运行在主线程旁边的线程中运行时从控制台拉出(在读取之前检查扫描仪是否有下一行),有一次我需要启动一个子进程,该子进程也需要从控制台读取。我有一个类用于运行命令并获取它们的输出并将输入从父进程的控制台传递给它们。从 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)

无论我按什么其他键,只要按 Enter 就会发生此错误,控制台也不允许我输入任何内容。这是将控制台输入传递到子进程的代码:

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()

        }

}

我尝试将 is 变成扫描仪并在其上使用 hasNext() 但这只会导致新问题并且不能修复旧问题,它确实允许我在 Windows 控制台中输入但按 Enter 仍然会导致相同的错误。

4

0 回答 0