Karthi
Karthi

Reputation: 3489

Convert Uint8Array to string in javascript

I'm running where *.exe to list all the exe from windows in electron application.and then launch some apps.It returns result in Uint8Array format.

const { execSync } = require('child_process');
const exeFiles=execSync('where *.exe');
console.log( exeFiles); // this returns [97, 92,79,....]
console.log(exeFiles.toString());
// returns
//C:\Windows\System32\cacls.exe                                                                                           //C:\Windows\System32\calc.exe...        

I want result to be

[C:\Windows\System32\cacls.exe,C:\Windows\System32\calc.exe,...]        

Upvotes: 0

Views: 239

Answers (1)

Avinash
Avinash

Reputation: 1994

if you want the result as an array, you can split the string based on the newline character and remove the last element

const resultArray = exeFiles.toString().split("\n")
resultArray.pop() // since last element will be empty string
console.log(resultArray);

Upvotes: 1

Related Questions