javascript - 如何在NW.JS中使用Node自動重啟進程?
問題描述
我這個項目是基于NW.JS開發的,當滿足某個條件后,我需要重啟客戶端,但小弟我對NODE實在是不夠了解,需要各位大神幫忙解決,謝謝了!!無論是nw.js的方法亦或node的方法都行,只要能重啟程序就好~
問題解答
回答1:var nwRestart = function () { var child, child_process = require(’child_process’); if (process.platform == 'darwin') {child = child_process.spawn('open', ['-n', '-a', process.execPath.match(/^([^0]+?.app)//)[1]], { detached: true }); } else {child = child_process.spawn(process.execPath, [], { detached: true }); } child.unref(); require('nw.gui').Window.get().hide(); process._nw_app.quit();};nwRestart();
這個適用于比較老的nw客戶端,如果使用的nw版本比較新的話,需要相應的修改下,主要是最后的獲取nw_app進行退出
回答2:@QiCheen 太感謝了~謝謝!
相關文章:
1. 關于docker下的nginx壓力測試2. angular.js使用$resource服務把數據存入mongodb的問題。3. angular.js - angularjs的自定義過濾器如何給文字加顏色?4. docker-machine添加一個已有的docker主機問題5. 為什么我ping不通我的docker容器呢???6. docker安裝后出現Cannot connect to the Docker daemon.7. docker - 如何修改運行中容器的配置8. nignx - docker內nginx 80端口被占用9. Docker for Mac 創建的dnsmasq容器連不上/不工作的問題10. docker鏡像push報錯
