Un exemple très rapide, je dois faire quelque chose comme je l'ai dit plus tôt est la suivante:
private void executeCommand(string programFilePath, string commandLineArgs, string workingDirectory)
{
Process myProcess = new Process();
myProcess.StartInfo.WorkingDirectory = workingDirectory;
myProcess.StartInfo.FileName = programFilePath;
myProcess.StartInfo.Arguments = commandLineArgs;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.Start();
StreamReader sOut = myProcess.StandardOutput;
StreamReader sErr = myProcess.StandardError;
try
{
string str;
// reading errors and output async...
while ((str = sOut.ReadLine()) != null && !sOut.EndOfStream)
{
logMessage(str + Environment.NewLine, true);
Application.DoEvents();
sOut.BaseStream.Flush();
}
while ((str = sErr.ReadLine()) != null && !sErr.EndOfStream)
{
logError(str + Environment.NewLine, true);
Application.DoEvents();
sErr.BaseStream.Flush();
}
myProcess.WaitForExit();
}
finally
{
sOut.Close();
sErr.Close();
}
}
sûrement ce n'est pas parfait, mais il a travaillé lors de l'exécution d'un script Powershell, je voyais la sortie dans une mise à jour de zone de texte multiligne chaque fois que quelque chose de nouveau est sorti, la méthode qui a mis à jour ma zone de texte était le logMessage()
Est-il géré C++? Vous pouvez l'utiliser directement. S'il n'est pas géré, vous pouvez utiliser la classe 'Process' pour lancer un processus (l'application console). –