I'm working on a launcher application for software. Cant seam to figure out how to launch another application onclick of a button in my NWJS app. I've done it before on an HTA back in the day to launch my video games, but cant seam to figure it out on here. On the hta I had to spawn a bat file on click then the bat script ran the program.
My button I've made:
<span name="SystemWrapper3" id="SystemWrapper3" class="SystemWrapper3">
<input type="button" value="Calculator" name="SystemInput3" id="SystemInput3" class="SystemInput3" />
<i class="fa-solid fa-square-root-variable fa-lg" id="SystemIcon4"></i>
</span>
I've been looking into it I'm still pretty new to this. I've tried several solutions I've found looking stuff up online but they failed to work. idk if it is version incompatibility or what? I'm using NWJS 0.64.1 Win64 It may or may not end up being a NWJS app I'm launching, it might be just a regular exe. I'm not sure if there is different requirements for doing both.
EDIT::::
I've found this but I'm not sure how to call this code onclick of my button? Maybe make it a function? Then call the function name with onclick="myfunc()"?
var exec = require('child_process').execFile;
exec('C:/asd/test.exe', function(err, data) {
console.log(err)
console.log(data.toString());
});
EDIT2::::
So i tried this and several variations and still no luck. i called it from my button with onclick="launchbat()".
<script type="text/javascript">
function launchbat() {
var exec = require('child_process').execFile;
exec('"C:\Users\Dustin Angeletti\OneDrive\Documents\bat.bat"', function(err, data) {
console.log(err)
console.log(data.toString());
});
}
</script>
Figured it out. Quite simple my first approach and second works fine. My problem the whole time was using backslashes like in the true file path. You have to use forward slashes. Very odd. This works for relative and absolute paths.
function AppLaunch7() {
const path = require('path');
nw.Shell.openItem(path.resolve('D:/SECURE DRIVE/SYSTEM CORE/SECURE CALC/SECURE CALC.exe'));
}
<div name="SystemWrapper1" id="SystemWrapper1" class="SystemWrapper1" onclick="AppLaunch7()">
<input type="button" value="Documents" name="SystemInput1" id="SystemInput1" class="SystemInput1" />
<span name="SystemIcon1" id="SystemIcon1" class="material-icons">description</span>
</div>