Hello Udhay,
Thanks for posting your query here and we are happy to assist you regarding the PowerShell command.
The Start-Process cmdlet starts one or more processes on the local computer. By default, Start-Process creates a new process that inherits all the environment variables that are defined in the current process.
You can use following command to redirect the output / error to each file. Try placing your command to run PostgreSQL exe in input file. Following code works for me.
$processOptions = @{
FilePath = "ping.exe"
RedirectStandardInput = "C:\Users\O00\OneDrive\Desktop\PS-Scripts\TestSort.txt"
RedirectStandardOutput = "C:\Users\O00\OneDrive\Desktop\PS-Scripts\Sorted.txt"
RedirectStandardError = "C:\Users\O00\OneDrive\Desktop\PS-Scripts\SortError.txt"
UseNewEnvironment = $true
}
Start-Process @processOptions
Please find additional information in below link.
Also try following option. Instead of returning the data to host, try to redirect to any file.
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "C:\Program Files\PostgreSQL\14\bin\pg_basebackup.exe"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "-D G:\FULL_Backup\Test", "-Ft", "-z", "-R", "-U pgbackup", "-w", "-P"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
Write-Host "stdout: $stdout"
Write-Host "stderr: $stderr"
Write-Host "exit code: " + $p.ExitCode
Please feel to reply if you have any additional questions.
Here is a helpful page with information about Windows PowerShell
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/powershell
---------------------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept as answer.--

