1

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 -->
}

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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().

Comments

Your Answer

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.