Methods
(async) WProcessStatus(name) → {Promise}
- Description:
列出指定程序名稱的pid與狀態之清單
- Source:
Example
async function test() {
let name = 'chrome.exe'
let opt = {}
let rs = await WProcessStatus(name, opt)
console.log('rs', rs)
// rs => [
// {
// name: 'chrome.exe',
// pid: 400,
// ram: 169404,
// username: '{username}',
// status: 'running'
// },
// {
// name: 'chrome.exe',
// pid: 11648,
// ram: 2300,
// username: '{username}',
// status: 'stopped'
// }
// {
// name: 'chrome.exe',
// pid: 4984,
// ram: 211720,
// username: '{username}',
// status: 'running'
// },
// ...
// ]
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name | Type | Description |
|---|---|---|
name |
String | 輸入程序名稱字串 |
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(async) autoDownloadFiles() → {Promise}
- Description:
自動定位processStatus.exe,若無檔案則自動下載,回傳processStatus.exe的絕對路徑
依序偵測當前工作路徑的src/與node_modules/w-process-status/src/,皆無processStatus.exe時, 代表安裝時npm封鎖scripts致postinstall未執行,故自動調用downloadFiles重新下載
供w-process-status自身與其他依賴w-process-status的套件調用,無須各自實作偵測與下載邏輯
因processStatus.exe只能用於Windows作業系統,故調用前須自行檢核作業系統
- Source:
Example
import autoDownloadFiles from 'w-process-status/src/autoDownloadFiles.mjs'
async function test() {
//autoDownloadFiles, 無processStatus.exe時自動下載, 下載失敗則reject
let { fpExe } = await autoDownloadFiles()
console.log('fpExe', fpExe)
// fpExe D:\xxx\node_modules\w-process-status\src\processStatus.exe
}
test()
.catch((err) => {
console.log('catch', err)
})
Returns:
回傳Promise,resolve回傳執行檔路徑物件,內含fpExe為processStatus.exe的絕對路徑字串,reject回傳錯誤訊息
- Type
- Promise