0

I am modifying dummy file a.gradle which in on my desktop and then trying to replace it with actual Github project's gradle file under git directory on my local machine using below PowerShell command

Get-Content "a.gradle" -replace 'foo', 'bar'| Out-File "b.gradle"

But When I tried to run gradlw test command it is throwing an error:

unexpected char: 0x0 @ line 1, column 4. ??a p p l y p l u g i n : ' j a v a '

I tried appending "encoding "UTF8" after Out-File command but it is not working.

Ansgar Wiechers
  • 175,025
  • 22
  • 204
  • 278
Shah
  • 493
  • 4
  • 10
  • 1
    `Out-File` / `>`, as of PSv5.1, create "Unicode" (UTF16-LE) files by default, where each character is represented by (typically) 2 bytes. `-Encoding UTF8` produces UTF-8, but invariably prepends a BOM to the output file. Most Unix-heritage utilities can't handle either, and expect UTF-8 _without a BOM_. The question linked to by @JamesQMurphy has answers with solutions. – mklement0 Sep 12 '17 at 04:05
  • Additional to the above comments keep in mind that powershell cmdlets that write to a file have the tendency to add lines when not necessary. Just use the internal dotnet sdk form the `System.IO.File` class or use the `-NoNewLine` parameter when available. – Alex Sarafian Sep 12 '17 at 06:46

0 Answers0