Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell换行字符数为59个_Powershell_Nuget_Powershell Ise - Fatal编程技术网

Powershell换行字符数为59个

Powershell换行字符数为59个,powershell,nuget,powershell-ise,Powershell,Nuget,Powershell Ise,使用此命令,结果分为两行,第一行修剪59个字符,第二行修剪所有其他字符 $command ='nuget.exe list "Json.NET" -source "https://www.nuget.org/api/v2/"' (Invoke-Expression "$command") | out-file C:\test.txt 它看起来像一个奇怪的单词包装,只出现在Windows PowerShell ISE中(PowerShell.exe工作正常) 增加缓冲区大小对我不起作用 $hos

使用此命令,结果分为两行,第一行修剪59个字符,第二行修剪所有其他字符

$command ='nuget.exe list "Json.NET" -source "https://www.nuget.org/api/v2/"'
(Invoke-Expression "$command") | out-file C:\test.txt
它看起来像一个奇怪的单词包装,只出现在Windows PowerShell ISE中(PowerShell.exe工作正常)

增加缓冲区大小对我不起作用

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

start-process $nugetExe $command -wait -WindowStyle Hidden -RedirectStandardOutput C:\test.txt -RedirectStandardError C:\error.txt
但它只有在排除“RedirectStandardError”的情况下才起作用,如果它存在的话——包装仍然存在 如果我使用

$process.StartInfo.RedirectStandardError = $true;  

尝试在
输出文件上使用
-Width
参数,例如:

nuget.exe list "Json.NET" -source "https://www.nuget.org/api/v2/" | 
    Out-File C:\test.txt -Width 256

$command
变量中有什么?第一行是否总是修剪为59个字符(例如set
$command=''0'*200'
)?它是get-nuget-packages-list命令,如:.nuget.exe-list“Json.NET”-source“”,如果包名太长,则为59个字符。看起来nuget负责包装,并且包装在窗口宽度上。您必须设置
$Host.UI.RawUI.WindowSize
。我不使用nuget,所以我不确定是否还有其他选项。不幸的是,它没有帮助可能是nugget当时正在包装文本。从cmd.exe中尝试相同的命令,看看它是否在控制台上包装在59处。powershell.exe和cmd.exe工作正常,如果我从它们调用nuget.exe如果执行此
“-”*64 | Out文件c:\test.txt
是ISE,它是否也在59处换行?@user2586803它似乎与此问题有关:由于ISE没有
$Host.UI.RawUI.WindowSize
,nuget默认宽度为60。您可以使用命令“nuget.exe list”Json.NET“-source”从ISE启动powershell控制台https://www.nuget.org/api/v2/|输出文件c:\nugettest.txt'
,或者直接使用控制台。