0
我認爲這將是非常直接的,但我有問題的流程類和重定向標準輸出。我試圖運行一個Java程序(Craftbukkit,Minecraft服務器軟件)並重定向輸出。重定向標準輸出數據「>」
一切正常,前兩行
210 recipes
27 achievements
,但該行每一個走的是簡單的線「>」後
>
>
>
>
>
正確的輸出應該是這樣的
210 recipes
27 achievements
20:52:45 [INFO] Starting minecraft server version 1.4.6
20:52:45 [INFO] Loading properties
20:52:45 [INFO] Default game type: SURVIVAL
20:52:45 [INFO] Generating keypair
20:52:46 [INFO] Starting Minecraft server on *:25565
20:52:48 [INFO] This server is running CraftBukkit version git-Bukkit-1.4.6-R0.3
-5-g82c58b5-b2589jnks (MC: 1.4.6) (Implementing API version 1.4.6-R0.4-SNAPSHOT)
20:52:49 [INFO] Preparing level "world"
我放入一個斷點來查看e.Data的值是什麼,輸入字符串值「>」。所以問題不在於輸出。
代碼:
static void Main(string[] args)
{
ServerProcess p = new ServerProcess("craftbukkit.jar");
}
class ServerProcess
{
public ServerProcess(string server_jar)
{
ProcessStartInfo pInfo = new ProcessStartInfo("java", "-jar " + server_jar);
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
pInfo.UseShellExecute = false;
Process p = new Process();
p.StartInfo = pInfo;
p.OutputDataReceived += new DataReceivedEventHandler(ServerOutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(ServerErrorDataReceived);
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();
}
static void ServerErrorDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine("Error: {0}", e.Data);
}
static void ServerOutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine("{0}", e.Data);
}
}
有誰知道發生了什麼事?任何幫助,將不勝感激。
這工作,謝謝。奇怪它認爲他們是錯誤的,但我會採取任何行動。 – pix64
@ user1952744歡迎您:) – VladL