Part of this program checks if java is installed and continues checking every two seconds, then proceeds once it's installed, how do i make it update the terminal context to be able to execute the java command without restarting the program itself?
var javaCheckLoop = setInterval(function(){
checkJava(function(res){
if(res){
//java installed, continue
} else {
//java not found, keep checking
}
})
},2000)
function checkJava(callback) {
//need terminal context to update so it can detect java
var c = require('child_process').exec('java', (error, stdout, stderr) => {
callback(stderr.includes("Usage")); //returns true if java is available via cmd
});
};
while I did find a way to detect if java had been installed I didn't find a way to update the terminal context. I was previously trying to spawn java as a command, but the trick lied in the registry, which updates in real time and can be used to detect if java had been installed.
require('child_process').exec('reg query "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"', (error, data) => {
callback(String(data).includes("javapath")); //returns true if javapath is present in the environment variables
});