Skip to content

Text decoding error when returning to resolve characters containing non-English #151

Description

@Danjuanlab

I want to use powershell to list the installed programs on the computer and determine if the user has installed the target program. But when running in vscode, when the return value contains Chinese, the decoding error of the result leads to garbled characters.

After some inquiries, I know that the problem is because the default encoding in the Chinese system is gbk. According to the existing solutions on the Internet, either modify the registry of the local computer or modify the language of the computer. But neither solution can be used as a software tool for customers.

OS:win11 64bit
node-powershell:5.0.1

Here is my demo code.

import { PowerShell } from "node-powershell";
const powershellInstance = async () => {
  const ps = new PowerShell({
    debug: true,
    outputEncoding:'utf-8',
    executableOptions: {
      '-ExecutionPolicy': 'Bypass',
      '-NoProfile': true,
    },
  });

  try {
    const Name = ('^Google Chrome');
    const printCommand = PowerShell.command `Get-ItemProperty -Path "HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*" | Select-Object DisplayName, DisplayVersion, InstallDate, Version`;
    const  result = await ps.invoke(printCommand);

    console.log('11',result);
  } catch (error) {
    console.error(error);
  } finally {
    await ps.dispose();
  }
};
powershellInstance();

luanma
luanma2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions