0

Using this command result is divided on two lines, first trimmed on 59 characters, second - all other characters

$command ='nuget.exe list "Json.NET" -source "https://www.nuget.org/api/v2/"'
(Invoke-Expression "$command") | out-file C:\test.txt

It looks like some strange word wrapping and appears only in Windows PowerShell ISE (Powershell.exe works fine)

Increase the buffer size doesn't work for me

$host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size(512,50)

this works

start-process $nugetExe $command -wait -WindowStyle Hidden -RedirectStandardOutput C:\test.txt -RedirectStandardError C:\error.txt

but it works only if exclude "RedirectStandardError", if it exist - wrapping still in place The same issue if I use

$process.StartInfo.RedirectStandardError = $true;  
Sergey
  • 180
  • 1
  • 9
  • What is in the `$command` variable? Is the first line always trimmed to 59 chars (e.g. set `$command = '"0"*200'`)? – Rynant Jan 08 '14 at 15:09
  • it's get nuget packages list command like: .nuget.exe list "Json.NET" -source "https://nuget.org/api/v2/", and no, 59 characters only if package name is too long – Sergey Jan 08 '14 at 15:11
  • It looks like nuget is responsible for the wrapping, and it wraps on the window width. You will have to set `$Host.UI.RawUI.WindowSize`. I don't use nuget, so I'm not sure if there is another option. – Rynant Jan 08 '14 at 16:56
  • I would use set-content over out-file. – js2010 Nov 21 '22 at 20:34

3 Answers3

0

Try using the -Width parameter on the Out-File e.g.:

nuget.exe list "Json.NET" -source "https://www.nuget.org/api/v2/" | 
    Out-File C:\test.txt -Width 256
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • unfortunately it didn't help – Sergey Jan 09 '14 at 08:11
  • Perhaps it is nugget that is wrapping the text then. Try the same command from cmd.exe and see if it wraps at 59 on the console. – Keith Hill Jan 09 '14 at 16:22
  • powershell.exe and cmd.exe works properly if I call nuget.exe from them – Sergey Jan 09 '14 at 16:27
  • If you execute this `"-" * 64 | Out-File c:\test.txt` is ISE, does it also wrap at 59? – Keith Hill Jan 09 '14 at 18:25
  • no,it works properly, it looks like a problem between NuGet.exe and PowerShell ISE output, cause when I call only NuGet.exe and run "get list" - all is ok, but when I call NuGet.exe through powershell then I have wrapping – Sergey Jan 10 '14 at 13:42
  • 1
    @user2586803 It looks like it is related to this issue: http://nuget.codeplex.com/workitem/3673 Since the ISE does not have `$Host.UI.RawUI.WindowSize`, nuget defaults to a width of 60. You could start the powershell console from the ISE with `start powershell -wait -ArgumentList -command, 'nuget.exe list "Json.NET" -source "https://www.nuget.org/api/v2/"| out-file c:\nugettest.txt'`, or just use the console directly. – Rynant Jan 10 '14 at 14:05
0

(I had a similar problem in the far future) nuget.exe will wrap at 80 characters in macOS if the output is redirected: https://github.com/NuGet/Home/issues/10198

The fix was merged into the 5.9 release.

Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
0

Set-content won't add the extra rendering. Invoke-expression isn't needed.

nuget list Json.NET -source https://www.nuget.org/api/v2/ | set-content C:\test.txt
js2010
  • 23,033
  • 6
  • 64
  • 66