process.StandardInput에서 Stream에 명령을 보내려면 함수를 만들어야합니다. 작성자가 초기화되지 않은 오류가 있습니다. 이 문제를 어떻게 해결할 수 있습니까?함수 밖에서 StreamWriter 또는 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();
}
}
}
정확히 어떤 문제가 있습니까? 나는 당신의 코드가 컴파일 될 것이라고 생각하지 않는다. –
'while (true)'을 벗어날 방법이 없습니다. 대담한 움직임 :) –
아야 !! 사용자가 콘솔을 빠져 나가지 않고 콘솔에 들어가라고 계속 묻는 것은 너무 무례합니다. –