Bonjour,

j'essaye depuis quelques jours de rediriger la sortie d'un processus dans une RichTextBox avec Powershell mais sans succès...

Voici le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
$process = New-Object System.Diagnostics.Process
$process.StartInfo.Filename = "scanstate.exe"
$process.StartInfo.Arguments = " $storePath /i:$MIGUSERPATH /v:$VERBOSITY /ue:*\* /ui:NTKD0\$username /encrypt:$ENCRYPTION /keyfile:$KEYPATH$username.key /c"
$process.StartInfo.CreateNoWindow = $true
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.RedirectStandardError = $true
$process.StartInfo.RedirectStandardOutput = $true
 
Register-ObjectEvent -InputObject $process -EventName OutputDataReceived -action {
	if (-not [string]::IsNullOrEmpty($EventArgs.data))
	{
		$LogBox.AppendText([Environment]::NewLine + $EventArgs.data)
	}
} | Out-Null
 
Register-ObjectEvent -InputObject $process -EventName ErrorDataReceived -action {
	if (-not [string]::IsNullOrEmpty($EventArgs.data))
	{
		$LogBox.AppendText([Environment]::NewLine + $EventArgs.data)
	}
} | Out-Null
 
$process.start()
$process.BeginOutputReadLine()
$process.BeginErrorReadLine()
 
while ( ! $process.HasExited)
{
	[System.Windows.Forms.Application]::DoEvents()
}
Le processus tourne correctement, pas de soucis à ce niveau là mais par contre la sortie du process n'apparait pas dans la RichTextBox.
J'ai essayé DataReceivedEventHandler avec une fonction déléguée mais je n'arrive pas à implémenter correctement ce système avec powershell.

Avez-vous une idée, une piste pour m'aider ?
Merci d'avance.