Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think I have your answer. I'm working with Powershell for a while and created several build systems. Sorry if the script is a bit long, but it works.</p> <pre><code>$dir = &lt;your dir&gt; $global:log = &lt;your log file which must be in the global scope&gt; # Not global = won't work function Create-Process { $process = New-Object -TypeName System.Diagnostics.Process $process.StartInfo.CreateNoWindow = $false $process.StartInfo.RedirectStandardError = $true $process.StartInfo.UseShellExecute = $false return $process } function Terminate-Process { param([System.Diagnostics.Process]$process) $code = $process.ExitCode $process.Close() $process.Dispose() Remove-Variable process return $code } function Launch-Process { param([System.Diagnostics.Process]$process, [string]$log, [int]$timeout = 0) $errorjob = Register-ObjectEvent -InputObject $process -EventName ErrorDataReceived -SourceIdentifier Common.LaunchProcess.Error -action { if(-not [string]::IsNullOrEmpty($EventArgs.data)) { "ERROR - $($EventArgs.data)" | Out-File $log -Encoding ASCII -Append Write-Host "ERROR - $($EventArgs.data)" } } $outputjob = Register-ObjectEvent -InputObject $process -EventName OutputDataReceived -SourceIdentifier Common.LaunchProcess.Output -action { if(-not [string]::IsNullOrEmpty($EventArgs.data)) { "Out - $($EventArgs.data)" | Out-File $log -Encoding ASCII -Append Write-Host "Out - $($EventArgs.data)" } } if($errorjob -eq $null) { "ERROR - The error job is null" | Out-File $log -Encoding ASCII -Append Write-Host "ERROR - The error job is null" } if($outputjob -eq $null) { "ERROR - The output job is null" | Out-File $log -Encoding ASCII -Append Write-Host "ERROR - The output job is null" } $process.Start() $process.BeginErrorReadLine() if($process.StartInfo.RedirectStandardOutput) { $process.BeginOutputReadLine() } $ret = $null if($timeout -eq 0) { $process.WaitForExit() $ret = $true } else { if(-not($process.WaitForExit($timeout))) { Write-Host "ERROR - The process is not completed, after the specified timeout: $($timeout)" $ret = $false } else { $ret = $true } } # Cancel the event registrations Remove-Event * -ErrorAction SilentlyContinue Unregister-Event -SourceIdentifier Common.LaunchProcess.Error Unregister-Event -SourceIdentifier Common.LaunchProcess.Output Stop-Job $errorjob.Id Remove-Job $errorjob.Id Stop-Job $outputjob.Id Remove-Job $outputjob.Id $ret } $repo = &lt;your repo&gt; $process = Create-Process $process.StartInfo.RedirectStandardOutput = $true $process.StartInfo.FileName = "git.exe" $process.StartInfo.Arguments = "clone $($repo)" $process.StartInfo.WorkingDirectory = $dir Launch-Process $process $global:log Terminate-Process $process </code></pre> <p>The log file must be in the global scope because the routine which runs the event processing is not in the script scope.</p> <p>Sample of my log file:</p> <p>Out - Cloning into ''... ERROR - Checking out files: 22% (666/2971)<br> ERROR - Checking out files: 23% (684/2971)<br> ERROR - Checking out files: 24% (714/2971) </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload