I am writing an Electron app. I have this very simple function which at the moment is just returning an empty array:
async GetStuff()
{
var result:string[] = [];
var bExists = false;
var exec = require('child_process').exec;
exec("tasklist", (err:any, stdout:any, stderr:any) => {
err = err;
stderr = stderr;
bExists = stdout.toLowerCase().indexOf("unixsrv.exe") > -1;
});
return result
}
As it is, it correctly reports if a process named "unixsrv.exe" is running or not.
Thing is, the function as it is will first hit the "return result" line and later will hit the "bExists = " line.
How can modify the above so that I do not return until I have the answer as to whether or not the process exists?
More generically: How can I synchronously test whether a process is running or not?
Thanks for any help.
I have found the answer that works for me here:
node.js how to check a process is running by the process name?
It is the answer posted there by Christiaan Maks