Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this powershell snippet produce extra blank lines?

Tags:

powershell

This command will produce 1 extra line at the top and 3 more at the bottom.

Get-Process | select Name  | ft -HideTableHeaders | Out-File .\process.txt

The same thing happens with other lists such as reading a directory.

like image 380
wtjones Avatar asked Apr 03 '12 13:04

wtjones


2 Answers

Same result as in previous answer, but in another syntax:

Get-Process | foreach{ $_.Name}  > .\process.txt

There still is empty line in the end, though

like image 167
Andrey Marchuk Avatar answered Sep 19 '22 12:09

Andrey Marchuk


You can turn it into a string and trim it:

(Get-Process | select Name  | ft -HideTableHeaders | Out-String).Trim() | Out-File .\process.txt

Rather than three, there is now only one empty line at the end.

like image 29
Peter Hahndorf Avatar answered Sep 21 '22 12:09

Peter Hahndorf