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.
This topic is 5 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
raphaelgj
Posts: 23
Last visit: Thu Aug 17, 2023 8:41 am

Output being cut in compiled EXE but not is PS Studio

Post 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!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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.
User avatar
raphaelgj
Posts: 23
Last visit: Thu Aug 17, 2023 8:41 am

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

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

What host are you packaging with?
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

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

Post 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
  1. $pshost = get-host
  2. $pswindow = $pshost.ui.rawui
  3. $newsize = $pswindow.buffersize
  4. $newsize.height = 3000
  5. $newsize.width = 150
  6. $pswindow.buffersize = $newsize
  7. $newsize = $pswindow.windowsize
  8. $newsize.height = 50
  9. $newsize.width = 150
  10. $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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

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

Post by Alexander Riedel »

As always James, you are way smarter than me.
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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.
User avatar
raphaelgj
Posts: 23
Last visit: Thu Aug 17, 2023 8:41 am

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

Post by raphaelgj »

jvierra wrote: Tue Nov 13, 2018 12: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.
This topic is 5 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked