Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF8 Encoding Issue in Windows #42

Closed
vquilon opened this issue Mar 5, 2020 · 2 comments · Fixed by #207
Closed

UTF8 Encoding Issue in Windows #42

vquilon opened this issue Mar 5, 2020 · 2 comments · Fixed by #207
Assignees
Labels
bug Something isn't working

Comments

@vquilon
Copy link

vquilon commented Mar 5, 2020

I use Intellij Idea in Windows, with the cp-1252 encoding by default on Windows. I try to execute a python script with the powershell because of problems with subprocess inputs on windows subsystem linux (wsl). The problem is when I try to execute, because powershell pick the encoding by default of windows
The content of the ps1 is:

python -c "print('█')"
python generate_dependencies.py

And the content of the python script is:

print("START", file=sys.stdout)
print("█")

And Im getting this weird results:

image

Is weird because the execution of the python script returns in cp-1252 and the python -c command inline return in weird encoding, I dont know which encoding is.

@ForNeVeR
Copy link
Collaborator

ForNeVeR commented Sep 18, 2023

For me, the issue is that the output is different for run from an OS terminal and for run from the plugin. It should be exactly the same.

I was able to fix it using a hacky workaround:

Index: src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellScriptCommandLineState.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellScriptCommandLineState.kt b/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellScriptCommandLineState.kt
--- a/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellScriptCommandLineState.kt	(revision Staged)
+++ b/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellScriptCommandLineState.kt	(date 1695076638030)
@@ -14,6 +14,7 @@
 import com.intellij.openapi.vfs.LocalFileSystem
 import com.intellij.plugin.powershell.lang.lsp.LSPInitMain
 import com.intellij.plugin.powershell.lang.lsp.languagehost.PowerShellNotInstalled
+import com.intellij.terminal.TerminalUiSettingsManager
 import java.io.File
 import java.util.regex.Pattern
 
@@ -29,7 +30,7 @@
         runConfiguration.getCommandOptions(),
         runConfiguration.scriptParameters
       )
-      val commandLine = PtyCommandLine(command)
+      val commandLine = PtyCommandLine(command).apply { withCharset(Charsets.UTF_8) }
       val project = runConfiguration.project
       val module = LocalFileSystem.getInstance().findFileByIoFile(File(runConfiguration.scriptPath))?.let {
         ProjectRootManager.getInstance(project).fileIndex.getModuleForFile(it)

I'll see how to properly fix it (I assume we should read the terminal encoding used by the IDE instead).

@ForNeVeR ForNeVeR added the bug Something isn't working label Sep 18, 2023
@ForNeVeR ForNeVeR self-assigned this Sep 18, 2023
@ForNeVeR
Copy link
Collaborator

ForNeVeR commented Mar 5, 2024

Please note that python -c "print('█')" in a .ps1 file only works if your PowerShell instance is able to read this from the file properly.

For a UTF-8 encoded file, you should either add UTF-8 BOM, or use a modern PowerShell version (6.0+).

We are thinking of switching to PowerShell Core by default if it's available, but that's topic of #176.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants