PowerShell 7.3 - implementing Using `Start-Process` for Background Tasks and Retrieving Output
I'm performance testing and I'm experimenting with This might be a silly question, but Hey everyone, I'm running into an issue that's driving me crazy. I've looked through the documentation and I'm still confused about I'm having trouble using `Start-Process` in PowerShell 7.3. I want to run a script in the background, but I need to capture its output for logging purposes. I used the following command to start the process: ```powershell $process = Start-Process -FilePath "C:\path\to\script.ps1" -ArgumentList "-param1 value1" -NoNewWindow -PassThru ``` However, when I try to retrieve the output using the `Read-Output` method, it doesn't seem to capture any data. The script itself is correct and works when run directly in the console. I added the `-Wait` flag to ensure the parent script waits for the child script to complete, but the output isn't being captured: ```powershell $process.WaitForExit() $output = $process.StandardOutput.ReadToEnd() ``` I also checked that `script.ps1` contains the necessary `Write-Output` commands to send data to the standard output. Instead of seeing the expected output, I get a blank string. I tried running the script in a different context using `-RedirectStandardOutput`, but I still faced the same scenario: ```powershell $process = Start-Process -FilePath "C:\path\to\script.ps1" -ArgumentList "-param1 value1" -NoNewWindow -RedirectStandardOutput "C:\path\to\output.txt" -PassThru ``` After running this, I checked `output.txt`, and it also remains empty. Any ideas on why I'm unable to capture the output when using `Start-Process`? I've looked into various forums and documentation, but nothing seems to address this specific scenario. I'm starting to think it might be related to how PowerShell handles output streams in the context of background tasks. Any help would be greatly appreciated! For context: I'm using Powershell on Windows. My development environment is Linux. Has anyone else encountered this? This is for a mobile app running on macOS. I'm working on a application that needs to handle this. I'd love to hear your thoughts on this.