Output being cut in compiled EXE but not is PS Studio

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
raphaelgj
Posts: 19
Joined: Tue Jun 19, 2018 10:19 am

Output being cut in compiled EXE but not is PS Studio

Post by raphaelgj » Mon Nov 12, 2018 1:33 pm

Wow this is weird.
I have this simple command showing name and directory output in a textbox :

$textboxContenu.text = Get-ChildItem -Path $($folderbrowsermoderndialog1.SelectedPath) -Recurse | select Name,Directory | Format-Table -AutoSize | Out-String

If i RUN (F5) the form in powershell studio, it shows the full directory name with scrollbars in the textbox since the path is long:

Code: Select all

Name                      Directory                                                                                                 
----                      ---------                                                                                                 
subf                                                                                                                                
Captivate AUTO-UPDATE.msi \\intra.zzzz.net\zzz\DepotDMLzzzt\Poste\Travail\zz25\POWzzLSTUDIO\DOSSIzzRE\szz    
twetse.txt                \\intra.zzzz.net\zzz\DepotDMLzzzt\Poste\Travail\zz25\POWzzLSTUDIO\DOSSIzzRE\szz    
If i COMPILE in EXE, when I run that EXE, the Directory property is cut showing "..." instead of the whole path:


Code: Select all

Name                      Directory                                            
----                      ---------                                            
subf                                                                           
Captivate AUTO-UPDATE.msi \\intra.zzzz.net\zzz\DepotDMLzzzt\Poste\T...
twetse.txt               \\intra.zzzz.net\zzz\DepotDMLzzzt\Poste\T...

Why is the EXE behaving differently than inside powershell studio and how do I get my full path?

Thanks!

User avatar
jvierra
Posts: 13485
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output being cut in compiled EXE but not is PS Studio

Post by jvierra » Mon Nov 12, 2018 1:57 pm

That is an issue of console width. It can be over come by increasing the console Window size.

Be sure you are using the correct host. Using a console host with a Forms script will truncate the output of Format-Table. I recommend not using Format-Table in a form. Use a plain text generator that creates a set of strings to add to the textbox.

User avatar
raphaelgj
Posts: 19
Joined: Tue Jun 19, 2018 10:19 am

Re: Output being cut in compiled EXE but not is PS Studio

Post by raphaelgj » Mon Nov 12, 2018 6:41 pm

How should it be approached code wise then ? Do I need to specify console width or change the command somehow? New to this issue of width being different in studio than compiled.

User avatar
jvierra
Posts: 13485
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output being cut in compiled EXE but not is PS Studio

Post by jvierra » Mon Nov 12, 2018 7:03 pm

What host are you packaging with?

User avatar
Alexander Riedel
Posts: 6915
Joined: Tue May 29, 2007 4:43 pm

Re: Output being cut in compiled EXE but not is PS Studio

Post by Alexander Riedel » Mon Nov 12, 2018 9:19 pm

PowerShell is a console language. So a lot of things assume by default an 80 by 25 character size console window.
That is why using Format-Table and the like is generally not a great idea when you are not using a console.

You *should* be able to use code like this

Code: Select all

$pshost = get-host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 150
$pswindow.buffersize = $newsize
$newsize = $pswindow.windowsize
$newsize.height = 50
$newsize.width = 150
$pswindow.windowsize = $newsize
to influence the size PowerShell internally uses as measuring shtick. Disclaimer: I have not tested this, if it works I wrote it, if not, I have no idea where i came from ...
Just kidding (https://blogs.technet.microsoft.com/heyscriptingguy/2006/12/04/how-can-i-expand-the-width-of-the-windows-powershell-console/)

The internal host of PowerShell Studio sets the width to something incredibly long to avoid output being cut-off.
Obviously the packager hosts use something smaller (like 128 x 80) by default.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 13485
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output being cut in compiled EXE but not is PS Studio

Post by jvierra » Tue Nov 13, 2018 1:42 am

There turns out to be an easier way to do this. Just set the width in Out-String. It defaults to current console width which is 80 if it has not been explicitly set to a different value.

Code: Select all

$textboxContenu.text = Get-ChildItem -Path $($folderbrowsermoderndialog1.SelectedPath) -Recurse | 
     select Name,Directory | 
     Format-Table -AutoSize | 
     Out-String -Width 300

User avatar
Alexander Riedel
Posts: 6915
Joined: Tue May 29, 2007 4:43 pm

Re: Output being cut in compiled EXE but not is PS Studio

Post by Alexander Riedel » Tue Nov 13, 2018 2:16 am

As always James, you are way smarter than me.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 13485
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output being cut in compiled EXE but not is PS Studio

Post by jvierra » Tue Nov 13, 2018 2:26 am

Nonsense. I just happened to remember the answer from some time ago with output to a file from the console. "Out-File" also has this parameter to avoid console limits.

Your method is likely what the commands are foing under the covers although there may be other ways.

User avatar
raphaelgj
Posts: 19
Joined: Tue Jun 19, 2018 10:19 am

Re: Output being cut in compiled EXE but not is PS Studio

Post by raphaelgj » Tue Nov 13, 2018 5:51 am

jvierra wrote:
Tue Nov 13, 2018 1:42 am
There turns out to be an easier way to do this. Just set the width in Out-String. It defaults to current console width which is 80 if it has not been explicitly set to a different value.

Code: Select all

$textboxContenu.text = Get-ChildItem -Path $($folderbrowsermoderndialog1.SelectedPath) -Recurse | 
     select Name,Directory | 
     Format-Table -AutoSize | 
     Out-String -Width 300

Thank you so much! Works perfect with width and makes a lot of sense. Simplicity is bliss.

Locked