0

I am running a virussoftware scan via command line and the output will list me some informations in german that has umlaute (ö, ä, ü). The command is something like "C:\Program Files\Antivirus\antivirus.exe" --console --scan C:\path\to\file

Running the command via cmd directly will display them correctly. When running it via exec those will be displayed as .

I found the question wrong encoding when using child_process spawn or exec under Windows where the answer was to use cmd /c chcp 65001>nul && together with my command but that did nothing for me.

In another question How to force UTF-8 in node js with exec process? the answer was something similar but with @chcp 65001 >nul & cmd /d/s/c . But using this will error out the message that "C:\Program is no command to run. Code used:

var code = "@chcp 65001 >nul & cmd /d/s/c \"C:\\Program Files\\Antivirus\\antivirus.exe\" --console --scan C:\\path\\to\\file"
exec(code, { encoding: "utf-8" }, (err, stdout, stderr) => {
 console.log(stdout)
 .... // some other code that writes in a file
})

Running @chcp 65001 >nul & cmd /d/s/c dir with filenames that have umlaute will work correctly. Just my command seems to be broken.

So I tried the second answer to use iconv-lite. The answer states that I need to insert the encoding string used by the cmd that I can find on the code page:

replace your encoding string rather than 'CP936'. You can found it in cmd.exe > Properties > codepage.

The codepage my cmd uses is 65001 (utf8) and providing CP65001 will error out with the message that this encoding is unknown. utf8 or utf-8 doesn't error out but also won't display the umlaute correctly..

I am in a bit of lost here. What can I do?

asked Feb 24, 2025 at 13:52
3
  • 1
    "But using this will error out the message that "C:\Program is no command to run". That sounds like incorrect escaping, which is a different issue than the encoding issue. Please post the exec() code that you were using. Commented Feb 24, 2025 at 13:57
  • 1
    Don't switch the code page with chcp, specify the encoding as in exec("\"C:\\Program Files\\Antivirus\\antivirus.exe\" --console --scan C:\\path\\to\\file", {encoding: "latin1"}, ...) Commented Feb 24, 2025 at 15:32
  • This is not a problem of your node.js script, but a problem of your environment. What's wrong with using your script in a batch file, as it was suggested? Commented Feb 24, 2025 at 15:50

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.