How to pipe all output of .exe execution in Powershell?
The problem is some output is being sent to STDERR and redirection works differently in PowerShell than in CMD.EXE.
How to redirect output of console program to a file in PowerShell has a good description of the problem and a clever workaround.
Basically, call CMD
with your executable as a parameter. Like this:
UPDATE
I fixed my code so it would actually work. :)
$args = '"username@ssh"@ftp.domain.com -b psftp.txt';$output = cmd /c psftp.exe $args 2`>`&1
Give this a try
$output = [string] (& psftp.exe 'username@ssh@ftp.domain.com' -b psftp.txt 2>&1)
There is a PowerShell bug about 2>&1
making error records. The [string]
cast works around it.