I've been struggling all morning to find a solution. I've gone through several tutorials, but I still can't wrap my head around how this should work.
In my Electron app, there is a button that, when clicked, should execute a batch file (hpm.bat).
Here's how I defined the button in my index.html file:
<button class="button" onclick="handleButtonClick()" style="background-color: #e24a4a; border: #e24a4a;"\>
And here are the functions for the buttons defined in my renderer.js file:
const childProcess = require("child_process");
function handleButtonClick() {
const bash_run = childProcess.spawn([C:\Users\NM\Desktop\Electron\hpm.bat]);
}
function handleButton2Click() {
alert('Button clicked!');
}
I've tried following various instructions from the Internet, but I just can't seem to get it to work. The alert('Button clicked!');
message works fine, but running the batch file proves to be a challenge.
Could someone please give me a clear explanation on how I can execute the batch file
C:\Users\NM\Desktop\Electron\hpm.bat
in Electron?
I've experimented with different codes found on Stack Overflow and YouTube, but no luck so far.