Vos chemins sont bons. Mais vous obtenez seulement la sortie entière à la fin. Je voulais la sortie lorsque le script était en cours d'exécution. Alors voilà, tout d'abord à peu près la même chose, mais j'ai twissé la sortie. Si vous avez des problèmes regarder: http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx
public void execute(string workingDirectory, string command)
{
// create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(workingDirectory + "\\" + "my.bat ", command);
procStartInfo.WorkingDirectory = workingDirectory;
//This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
//This means that it will be redirected to the Process.StandardError StreamReader. (same as StdOutput)
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
//This is importend, else some Events will not fire!
proc.EnableRaisingEvents = true;
// passing the Startinfo to the process
proc.StartInfo = procStartInfo;
// The given Funktion will be raised if the Process wants to print an output to consol
proc.OutputDataReceived += DoSomething;
// Std Error
proc.ErrorDataReceived += DoSomethingHorrible;
// If Batch File is finished this Event will be raised
proc.Exited += Exited;
}
Quelque chose est éteint, mais tout ce que vous avez l'idée ...
Le DoSomething est cette fonction:
void DoSomething(object sendingProcess, DataReceivedEventArgs outLine);
{
string current = outLine.Data;
}
Hope this helps
par 'Bash', voulez-vous dire' Batch'? –
@W_P: bash est un shell unix. –
@Brian: Je pense que W_P le sait. –