Je dois créer une fonction pour envoyer des commandes au flux depuis process.StandardInput. J'ai une erreur avec l'auteur ne pas être initialisé. Comment puis-je réparer cela?Utiliser StreamWriter ou Stream en dehors de la fonction
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();
}
}
}
Exactement quel problème avez-vous? Je ne pense pas que votre code va même compiler. –
'while (true)' sans moyen d'en sortir. mouvement audacieux :) –
Aïe !! C'est trop grossier de continuer à demander à l'utilisateur d'entrer sur la console sans en sortir .. –