2

I create powershell script to read a file int a step on TeamCity. If I read the file in Powershell app and put the next script, it's work fine, but when execute that inside a step of runner type "PowerShell" the encoding not working and some characters are without encoding (like a "áãéí" etc,etc)

$userDocuments = [environment]::getfolderpath("mydocuments")
$file= "myfile.txt"
$fullPath = Join-Path $userDocuments -ChildPath $file
Get-Content -Encoding UTF8 $fullPath

Someone help me please?

Thanks in advance

fipcurren88
  • 701
  • 5
  • 26
  • I don't understand your problem. `Get-Content -Encoding UTF8` reads the data from disk through a UTF8 decoder ... then what happens? Your script doesn't do anything else. Where does the output from Get-Content go? Where are the `áãéí` characters showing up? What do you mean by "read the file then put the next script"? – TessellatingHeckler Jan 05 '17 at 19:09
  • @TessellatingHeckler, If I execute the scrit in powershell, the contente are correct. – fipcurren88 Jan 05 '17 at 19:27
  • @TessellatingHeckler The output of his Get-Content command are dumped to the console. Because the script is being called via a TeamCity agent that captures the console output and records+displays it in the app GUI – Nick Jan 06 '17 at 06:31
  • @Nick well yes, but the PowerShell console [doesn't support Unicode characters](http://stackoverflow.com/a/5808445/478656) properly. Does "powershell app" mean ISE or customised prompt or other console host? I'm not familiar with TeamCity at all, but presumably this would be easier for TeamCity users to comment if fipcurren88 actually explained how they set it up and where the problem happens. Is it [this problem](http://stackoverflow.com/questions/9213241/), for example ? Not enough information to do anything but guess. – TessellatingHeckler Jan 06 '17 at 06:41

1 Answers1

8

There is a few config changes required to tell TeamCity to process the output as UTF-8 Can you read HERE under the heading Handling Output

To properly handle non-ASCII output from PowerShell, the correct encoding must be set both on the PowerShell side and on the TeamCity side.

To set the output encoding for PowerShell to UTF-8, add the following line to the beginning of your PowerShell script: [Console]::OutputEncoding = [System.Text.Encoding]::UTF8

To set the encoding on the TeamCity agent side, either set the java launch option -Dfile.encoding=UTF-8, or set the build configuration parameter teamcity.runner.commandline.stdstreams.encoding value to UTF-8

Nick
  • 1,783
  • 1
  • 15
  • 18