Extraneous Console Output Interfering with Progress Bar

Advertisement

aksarben
Joined:
Posts:
72

Extraneous Console Output Interfering with Progress Bar

Found the cause. According to https://winscp.net/forum/viewtopic.php?t=24979, the output is a JSON representation of TransferEventArgs. It was apparently triggered by the following line in my code:
$session.PutFileToDirectory($fileName, $folder, $remove, $options)
Don't know why PowerShell thought that line required output, since it’s like many of the examples I’ve seen. In any case, I simply declared a [WinSCP.TransferEventArgs]$result object elsewhere, prepended it to the above code line, and voila! The problem disappeared.

Bothersome that I don't understand why such a seemingly innocent line of code would cause that kind of problem. Ah well…

When I transfer, extraneous output is written to the console, and is interfering with my progress bar. I can't figure out where this output is coming from. It looks like this, written for each file:
Side        : Local
Destination : /bib\w/wright.htm
Length      : 571
Touch       : WinSCP.TouchEventArgs
Chmod       : 
Removal     : 
FileName    : C:\Users\John\Documents\tch\ssh\client\bib\w\wright.htm
Error       :
Is the .NET Assembly creating this output? How do I stop it?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,516
Location:
Prague, Czechia

Re: Extraneous Console Output Interfering with Progress Bar

That has nothing to do with WinSCP .NET assembly.
That's simply how PowerShell works. If a statement yields a result, PowerShell dumps it to a console. If you do not want to that (and you are not interested in the result), a common pattern is to pipe the result to Out-Null:
$session.PutFileToDirectory($fileName, $folder, $remove, $options) | Out-Null

Reply with quote

Advertisement

You can post new topics in this forum