我有一个PowerShell脚本,但在继续下一行之前,一些输出在任意点被截断。这真是令人讨厌。
例如,我可以使用
Write-Host
只要我需要,该行将继续运行(请注意,即在团队城市中运行,团队城市添加了一些前缀信息-但是,通过将输出传输到文件可以观察到相同的效果):
[10:04:45] [Step 5/7] - Found Windows Service at G:\TeamCityData\TeamCityBuildAgent-1\work\282b8abc9094651e\Artefacts\windows-services\WindowsService.Dummy\WindowsService.DummyService.exe
其他时候,输出似乎会在任意点被人为截断,就像在窗口中包装一样(窗口不存在)。
所以,这一行:
Copy-Item -Path $fullSourcePath -Destination $destPath -Recurse -Verbose -ErrorAction Stop
在团队城市中生成此输出(添加了一些前缀信息):
[10:04:46] [Step 5/7] VERBOSE: Performing the operation "Copy File" on target "Item:
[10:04:46] [Step 5/7] G:\TeamCityData\TeamCityBuildAgent-1\work\282b8abc9094651e\Artefacts\windows-services\WindowsService.Dummy\WindowsServi
[10:04:46] [Step 5/7] ce.DummyService.exe Destination:
[10:04:46] [Step 5/7] \\SERVER001\scheduled-tasks\ProductFolder\Dev\DummyWindowsService\WindowsService.DummyService.exe".
[10:04:46] [Step 5/7] VERBOSE: Performing the operation "Copy File" on target "Item:
[10:04:46] [Step 5/7] G:\TeamCityData\TeamCityBuildAgent-1\work\282b8abc9094651e\Artefacts\windows-services\WindowsService.Dummy\WindowsServi
[10:04:46] [Step 5/7] ce.DummyService.exe.config Destination:
[10:04:46] [Step 5/7] \\SERVER001\scheduled-tasks\ProductFolder\Dev\DummyWindowsService\WindowsService.DummyService.exe.config".
我该如何阻止这种荒谬?我希望输出在行尾正确地呈现换行符,而不是在文件名的中间。
更新
下面的评论表明,这是TeamCity获取输出的方式存在问题。但是,如果我直接在PowerShell控制台中执行类似的命令并将输出传输到文件,则会发生相同的问题。
命令:
copy-item -Path F:\logs -Destination .\ -Recurse -Verbose *> F:\logs\copy-item-output-1.txt
产生如下输出:
Performing the operation "Copy File" on target "Item: F:\logs\20161103-140649-ProductName.Program.log
Destination: F:\Destination\1234567890abcdefghijklmnopqrstuvwxyz\this-is-a-long-path-name-to-show-wrapping-issues-with-copy-it
em\logs\20161103-140649-ProductName.Program.log".
如您所见,它还跨行分割文件路径,即使它发送到文件,而不是控制台窗口。