我需要创建一个函数来从 process.StandardInput 向 Stream 发送命令。我有一个错误,作者没有被初始化。我怎样才能解决这个问题?
private StreamWriter writer;
private static void SendProcessCmd(string cmd)
{
writer.WriteLine(cmd);
}
public static void CreateProcess()
{
ProcessStartInfo processInfo = new ProcessStartInfo("java.exe", args);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardInput = true;
try
{
using (Process process = Process.Start(processInfo))
{
writer = new StreamWriter(process.StandardInput.BaseStream);
//writer = process.StandardInput;
while (true)
{
String strInput = Console.ReadLine();
writer.WriteLine(strInput);
}
process.WaitForExit();
}
}
}