Page 1 of 1

Output being cut in compiled EXE but not is PS Studio

Posted: Mon Nov 12, 2018 1:33 pm
by raphaelgj
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!

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

Posted: Mon Nov 12, 2018 1:57 pm
by jvierra
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.

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

Posted: Mon Nov 12, 2018 6:41 pm
by raphaelgj
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.

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

Posted: Mon Nov 12, 2018 7:03 pm
by jvierra
What host are you packaging with?

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

Posted: Mon Nov 12, 2018 9:19 pm
by Alexander Riedel
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.

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

Posted: Tue Nov 13, 2018 1:42 am
by jvierra
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

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

Posted: Tue Nov 13, 2018 2:16 am
by Alexander Riedel
As always James, you are way smarter than me.

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

Posted: Tue Nov 13, 2018 2:26 am
by jvierra
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.

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

Posted: Tue Nov 13, 2018 5:51 am
by raphaelgj
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.