Skip to content

Console output #702

@mcc85s

Description

@mcc85s

Greetings,

This is not an issue with Netradiant per se, however I'm curious to know how tools like (mbspc.exe/bspc.exe), qmap2.exe, etc. sends stuff to the console in your application, because I've been attempting to implement that into a WPF application I've been making that uses XAML and PowerShell that helps orchestrate the process of
compiling and packaging a map

I'm not trying to build something as complicated as Netradiant, however, I want to use PowerShell to wrap and log all of the things I'm doing to a particular map, or multiple. Being able to redirect the standard output or error output from these tools has crashed with virtually every (attempt/approach) I've made.

I even took some time to try out various other approaches that Microsoft Copilot suggested.

So like, if I run something like this:

$process = Start-Process -FilePath $Filepath -ArgumentList $ArgumentList -NoNewWindow -RedirectStandardOutput "output.txt" -RedirectStandardError "error.txt" -PassThru
$process.WaitForExit()

$output = Get-Content "output.txt"
$xerror = Get-Content "error.txt"

...that works, but the process has to complete before I can access or see any of that data.

But as soon as I try an approach like this...

$process = New-Object System.Diagnostics.Process
$process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo
$process.StartInfo.FileName = $Filepath
$Process.StartInfo.Arguments = $ArgumentList
$process.StartInfo.RedirectStandardOutput = $true
$process.StartInfo.RedirectStandardError = $true
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.CreateNoWindow = $true

$process.EnableRaisingEvents = $true

$process.add_OutputDataReceived({
    param($sender, $args)
    if ($args.Data -ne $null) {
        Write-Host $args.Data
    }
})

$process.add_ErrorDataReceived({
    param($sender, $args)
    if ($args.Data -ne $null) {
        Write-Host "ERROR: " + $args.Data
    }
})

$process.Start()
$process.BeginOutputReadLine()
$process.BeginErrorReadLine()

$process.WaitForExit()

...the process does something, but it locks up my console host and doesn't return anything to the screen, so I have to terminate the console host.

But I can see very clearly if I build the map using Netradiant, it updates the information on the fly.

Perhaps you could offer some insight...?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions