[英]How can I wait for a check to test if a process is running to finish?
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.事实上,它会正确报告名为“unixsrv.exe”的进程是否正在运行。
Thing is, the function as it is will first hit the "return result" line and later will hit the "bExists = " line.问题是,函数本身将首先点击“返回结果”行,然后再点击“bExists =”行。
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? node.js 如何通过进程名称检查进程是否正在运行?
It is the answer posted there by Christiaan Maks这是Christiaan Maks在那里发布的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.