I read Creating a child process with redirected inputs and outputs on MSDN.
And I redirected the output. But input redirection is different from this example in my case.
I performed java -jar xxx.jarin a child process. And redirect the input to stdinPipe successfully. But I found that the child process, jar, is not reading the input.
I redirected the input descriptor as follows:
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 environment
NULL, // use parent current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
When i use bSuccess = WriteFile(g_hChildStd_IN_Wr, pCmd, strlen(pCmd), &dwWritten, NULL);. It works fine on my small test jar file that is used System.out.println(), and System.in.read()for output and input.
jar, , . , , jar ConsoleReader(System.in, System.out). java. , - , ?
!
P.S. , , .
, , jline.console.ConsoleReader.readLine(">",null). java arg -nojline, !
jline.console.ConsoleReader. , - System.in.read() jline.console.ConsoleReader.readLine(">",null).
:
if (!useConsole) {
return;
}
jline.console.ConsoleReader bufferedreader = this.server.reader;
String s;
try {
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);
}
}
} catch (IOException ioexception) {
DedicatedServer.az().error("Exception handling console input", ioexception);
}
, jline.console.ConsoleReader.readline() jline.console.ConsoleReader.readLine(">",null).
.
jline
readline() readline (null, null). , " > " , - 493. , os (win8.1) if (!terminal.isSupported())? ? java .