Reputation: 426
How do you execute an executable in electron-js (with its path given)?
I want to start within my application any other application. My operating system is Windows, so I'm looking for answers for Windows, but when there is also a solution for Linux I'm not reluctant in getting to know this solution.
For Example:
function startApk() {
let path = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe";
<!-- Here I want my program to be executed -->
}
Upvotes: 1
Views: 811
Reputation: 116
According to the documentation, execFile() is more performant than exec():
The child_process.execFile() function is similar to child_process.exec() except that it does not spawn a shell by default. Rather, the specified executable file is spawned directly as a new process making it slightly more efficient than child_process.exec().
Upvotes: 0
Reputation: 426
One approach as I figured would be:
let path = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe";
exec(`"${path}"`, (error) => { // use extra "" around path when the path contains spaces
if (error) {
// command couldn't be executed, handle error
return;
}
});
I'm still open for other and better solutions.
Upvotes: 1