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.

2
  • 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. Commented Sep 12, 2017 at 4: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. Commented Sep 12, 2017 at 6:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.