简体   繁体   English

我如何等待检查以测试进程是否正在运行以完成?

[英]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.

相关问题 如何使用 javascript 承诺使一个函数等待另一个函数异步完成运行? - How can I use a javascript promise to make one function wait for another to finish running asynchronously? c#WebBrowser-如何在文档加载完成后等待javascript完成运行? - c# WebBrowser- How can I wait for javascript to finish running that runs when the document has finished loading? 如何让我的脚本等待jQuery动画完成? - How can I make my script wait for jQuery animate to finish? 如何等到 Reactjs 中的功能完成? - How can I wait until the functions finish in Reactjs? 如何在继续之前等待递归 function 完全完成? - How can I wait for a recursive function to completely finish before continuing? 如何让一个方法等待另一个方法完成? - How can I make a method wait for another method to finish? 我怎么等<script> appended to body to finish executing - How can I wait for <script> appended to body to finish executing 如何等待外部文件功能完成然后在main上继续? - How can I wait for an external file function to finish then continue on main? 如何等待getJSON在Mocha测试中完成? - How to wait for getJSON to finish in a Mocha test? Jest:在运行下一个测试之前等待异步测试完成 - Jest: Wait for an async test to finish before running the next one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM