MSDNでリダイレクトされた入力と出力を使用して子プロセスを作成することを読みました。
そして、出力をリダイレクトしましたが、私の場合、リダイレクト入力はこの例とは異なります。
子プロセスで実行java -jar xxx.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
.Itを使用すると、出力と入力にbSuccess = WriteFile(g_hChildStd_IN_Wr, pCmd, strlen(pCmd), &dwWritten, NULL);
使用した小さなテスト jar ファイルで完璧に実行されます。System.out.println()
System.in.read()
しかし、jar サーバーを実行すると、入力が無効になり、リダイレクトが失敗します。私が知っている唯一のことは、jar の使用です。私ConsoleReader(System.in, System.out)
は Java に慣れていません。
どうもありがとう!!
PSソースコードは、最初に指定されたリンクと同じです。
最後に、これjline.console.ConsoleReader.readLine(">",null)
が問題であることがわかりました。引数を指定してJavaを実行する-nojline
と、すべて問題ありません!
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. 1)コードがコードにぶつかりましたif (!terminal.isSupported())
か?または、ソースコードを理解していませんか?Javaに慣れていないのはとても難しいです。