使用管道和java重定向输入

使用管道和java重定向输入,java,windows,visual-c++,pipe,jline,Java,Windows,Visual C++,Pipe,Jline,我读过MSDN 我已经重定向了输出,但重定向输入和我的例子不同 我已经在子进程中运行了java-jarxxx.jar,并成功地将输入重定向到stdinPipe。但是我发现子进程jar没有读取输入 我重定向了输入句柄,如下所示: ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.hStdError = g_hChildStd_OUT_Wr;

我读过MSDN

我已经重定向了输出,但重定向输入和我的例子不同

我已经在子进程中运行了
java-jarxxx.jar
,并成功地将输入重定向到stdinPipe。但是我发现子进程jar没有读取输入

我重定向了输入句柄,如下所示:

ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
siStartInfo.cb = sizeof(STARTUPINFO); 
siStartInfo.hStdError = g_hChildStd_OUT_Wr;
siStartInfo.hStdOutput = g_hChildStd_OUT_Wr;
siStartInfo.hStdInput = g_hChildStd_IN_Rd;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;

// Create the child process. 

bSuccess = CreateProcess(NULL, 
    szCmdline,     // command line which I use "java -jar xxx.jar"
    NULL,          // process security attributes 
    NULL,          // primary thread security attributes 
    TRUE,          // handles are inherited 
    0,             // creation flags 
    NULL,          // use parent's environment 
    NULL,          // use parent's current directory 
    &siStartInfo,  // STARTUPINFO pointer 
    &piProcInfo);  // receives PROCESS_INFORMATION 
当我使用
bSuccess=WriteFile时(g_hChildStd_IN_Wr,pCmd,strlen(pCmd),&dwwrited,NULL)
。它在我的小测试jar文件上运行得非常好,该文件使用了
System.out.println()
System.in.read()
来输出和输入

但是当我运行jar服务器时,输入无效,重定向失败。我只知道jar使用了
ConsoleReader(System.in,System.out)
。我不熟悉java。那么有人知道是什么禁止我重定向输入吗

非常感谢

另外,源代码与开头给出的链接相同


最后我发现问题出在
jline.console.consolerereader.readLine(“>”,null)
上。我用arg
-nojline运行java,一切正常

我还没有读过jline.console.ConsoleReader的源代码。我很高兴有人能告诉我
System.in.read()
jline.console.ConsoleReader.readLine(“>”,null)

问题代码如下:

if (!useConsole) {
        return;
    }
    // CraftBukkit end

    jline.console.ConsoleReader bufferedreader = this.server.reader; // CraftBukkit
    String s;

    try {
        // CraftBukkit start - JLine disabling compatibility
        while (!this.server.isStopped() && this.server.isRunning()) {
            if (useJline) {
                s = bufferedreader.readLine(">", null);
            } else {
                s = bufferedreader.readLine();
            }
            if (s != null) {
                this.server.issueCommand(s, this.server);
            }
            // CraftBukkit end
        }
    } catch (IOException ioexception) {
        DedicatedServer.az().error("Exception handling console input", ioexception);
    }
因此,使用
jline.console.ConsoleReader.readline()
也不同于
jline.console.ConsoleReader.readline(“>”,null)

我会继续研究


readline()函数等于readline(null,null)。这意味着不会显示“>”提示,但根据第493行的源代码,其他提示是相同的。因此我怀疑是我的windows操作系统(win8.1)导致代码运行到
if(!terminal.isSupported())
代码中的原因?或者我还没有理解源代码?不熟悉java很难