【问题标题】:Node.js - Listening for system processNode.js - 监听系统进程
【发布时间】:2021-03-21 18:33:31
【问题描述】:

我正在寻找一种方法来检测何时使用 node.js 在我的计算机上启动特定进程。

我想要像 discord 一样的东西:当我开始游戏时,我希望我的应用程序能够检测到该游戏。

我在 child_process 环境和 Discord API 中进行了搜索,但没有发现任何可利用的东西

【问题讨论】:

标签: node.js process discord


【解决方案1】:

你可以使用chokidar:

const chokidar = require('chokidar');

// Initialize watcher.
const watcher = chokidar.watch('path/to/folder', { persistent: true });
 
// Add event listeners.
watcher
  .on('add', path => log(`File ${path} has been added`))
  .on('change', path => log(`File ${path} has been changed`))
  .on('unlink', path => log(`File ${path} has been removed`));
 
// More possible events.
watcher
  .on('addDir', path => log(`Directory ${path} has been added`))
  .on('unlinkDir', path => log(`Directory ${path} has been removed`))
  .on('error', error => log(`Watcher error: ${error}`))
  .on('ready', () => log('Initial scan complete. Ready for changes'))

【讨论】:

  • 我试过 chokidar 但我找不到启动应用程序时触发的事件(即:启动 chrome.exe 时的事件)
猜你喜欢
  • 2016-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多