standardinput not being redirected C#
문제
So I have a process (java commandline application) that is hidden with the output and input being redirected. I can read the output very easily and that works, but when I send a command it dosen't work.
I think that I have determined that the input is not being redirected because:
(A) When I send WriteLine(//command here); Flush
no command is acknowledged by the program
(B) When I unhide the cmd window (StartInfo.CreateNoWindow = false;
) I can enter commands and run them (in the cmd window) even though the StandardInput is being redirected (StartInfo.RedirectStandardInput = true;
)
Here is the code:
namespace bukkit
{
public partial class Form1 : Form
{
private static StringBuilder _txt = new StringBuilder();
private static bool _scrolled = false;
Process mncrft = new Process();
public Form1()
{
InitializeComponent();
mncrft.StartInfo.WorkingDirectory = Path.GetTempPath();
mncrft.StartInfo.Arguments = "-Xmx512M -Xms512M -jar C:\\mncrft\\mncrft.jar";
mncrft.StartInfo.FileName = "java.exe";
mncrft.StartInfo.UseShellExecute = false;
mncrft.StartInfo.RedirectStandardOutput = true;
mncrft.StartInfo.RedirectStandardError = true;
mncrft.StartInfo.RedirectStandardInput = true;
mncrft.StartInfo.CreateNoWindow = false;
mncrft.ErrorDataReceived += build_ErrorDataReceived;
//mncrft.OutputDataReceived += build_ErrorDataReceived;
mncrft.EnableRaisingEvents = true;
//mncrft.StandardInput.NewLine = "\r\n";
mncrft.Start();
mncrft.BeginOutputReadLine();
mncrft.BeginErrorReadLine();
}
private void Form1_Load(object sender, EventArgs e)
{
_txt.AppendLine("Starting Minecraft...");
}
private void Form1_Close(object sender, EventArgs e)
{
mncrft.Close();
}
static void build_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
string msg = e.Data;
if (msg != null && msg.Length > 0)
{
_txt.AppendLine(msg);
_scrolled = false;
}
}
private void mainTimer_Tick(object sender, EventArgs e)
{
if (_txt.Length > 0)
{
txtOutput.Text = _txt.ToString();
// scroll down
if (_scrolled == false)
{
txtOutput.SelectionStart = txtOutput.Text.Length;
txtOutput.ScrollToCaret();
_scrolled = true;
}
}
}
private void Execute_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0)
{
mncrft.StandardInput.WriteLine(textBox1.Text);
mncrft.StandardInput.Flush();
}
}
}
}
How can I redirect the input so that I can send commands?
Thanks, Adam
P.S: If this is confusing, just put a comment down and I will gladly clarify.
Answered
Thanks to Tim, Replace the following lines:
mncrft.StartInfo.FileName = "java.exe";
mncrft.StartInfo.Arguments = "-Xmx512M -Xms512M -jar C:\\mncrft\\mncrft.jar";
with:
mncrft.StartInfo.FileName = "java";
mncrft.StartInfo.Arguments = "-Xmx512M -Xms512M -jar C:\\mncrft\\bukkit.jar -nojline";
올바른 솔루션이 없습니다