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

characters encode error in powershell! #628

Closed
gyhyfj opened this issue May 23, 2023 · 3 comments
Closed

characters encode error in powershell! #628

gyhyfj opened this issue May 23, 2023 · 3 comments

Comments

@gyhyfj
Copy link

gyhyfj commented May 23, 2023

Expected Behavior

Expect to show terminal output characters in powershell encoded correctly

Actual Behavior

encode error like this:

Error: mv : ��·����D:\GitRepo\serverless\frontend-monorepo\apps\dalle-quasar\dist\spa���ķ��ʱ��ܾ���
����λ�� ��:1 �ַ�: 1
+ mv ./apps/dalle-quasar/dist/spa ./apps/dalle-nuxt3/public
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (D:\GitRepo\serv...quasar\dist\spa:DirectoryInfo) [Move-Item], IOException
    + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

    at file:https:///D:/GitRepo/serverless/frontend-monorepo/scripts/build-endev.mjs:5:8
    exit code: 1

Steps to Reproduce the Problem

  1. exec a mv command on powershell on win10 like await $mv ./apps/a/dist/spa ./apps/b/public``, witch is available on git bash
  2. then it will exit with code 1, but the output msg is encode error.

Specifications

  • Version: "zx": "^7.2.1"
  • Platform: PowerShell 7.3.4 + win10
@Artoria2e5
Copy link

Artoria2e5 commented Aug 28, 2023

There are layers to this problem.

  1. The encoding. zx actually does not handle encoding at all; it just uses whatever child_process says is the stderr string. For this I recommend you make a plain node version and reproduce it.
  2. mv being not found. Is it really in your $env:PATH?
  3. Using git bash mv. g-b mv is the MSYS2 mv, which shares the Cygwin mv issue of being different from windows (msvcrt) cmdline parsing. The result is that you can get weird behavior such as being unable to make echo.exe print C:\". Tracking PR for: "Cygwin: rewrite cmdline parser" mirror/newlib-cygwin#5 is the patch to fix it, but I'm just too drained to split it per requested.
  4. Well, actually forget about windows cmdline parsing, because powershell.exe does not do windows cmdline quoting right in the first place. That's Arguments for external executables aren't correctly escaped PowerShell/PowerShell#1995. I think they got it fixed in the newer stuff, but it's called pwsh.exe and not powershell.exe, and might still be gated behind a feature switch.

@antonmedv yeah. your quotePowerShell function is completely right for powershell-the-language, but if you call any external program you will find the arguments messed up. Try looping echo out to node: do node.exe -e 'console.log(process.argv.slice(1).join("\n"))' -- "Windows 'rulez!'" in powershell. And you will see it doesn't work at all because the double-quotes around \n are gone.

@gyhyfj
Copy link
Author

gyhyfj commented Aug 28, 2023

There are layers to this problem.

  1. The encoding. zx actually does not handle encoding at all; it just uses whatever child_process says is the stderr string. For this I recommend you make a plain node version and reproduce it.
  2. mv being not found. Is it really in your $env:PATH?
  3. Using git bash mv. g-b mv is the MSYS2 mv, which shares the Cygwin mv issue of being different from windows (msvcrt) cmdline parsing. The result is that you can get weird behavior such as being unable to make echo.exe print C:\". Tracking PR for: "Cygwin: rewrite cmdline parser" mirror/newlib-cygwin#5 is the patch to fix it, but I'm just too drained to split it per requested.
  4. Well, actually forget about windows cmdline parsing, because powershell.exe does not do windows cmdline quoting right in the first place. That's Arguments for external executables aren't correctly escaped PowerShell/PowerShell#1995. I think they got it fixed in the newer stuff, but it's called pwsh.exe and not powershell.exe, and might still be gated behind a feature switch.

@antonmedv yeah. your quotePowerShell function is completely right for powershell-the-language, but if you call any external program you will find the arguments messed up. Try looping echo out to node: do node.exe -e 'console.log(process.argv.slice(1).join("\n"))' -- "Windows 'rulez!'" in powershell. And you will see it doesn't work at all because the double-quotes around \n are gone.

Thank you very much

@gyhyfj gyhyfj closed this as completed Aug 28, 2023
@antonmedv
Copy link
Collaborator

Ohhh, windows.

I'm actually thinking of using bash by default on windows as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants