{"id":357,"date":"2018-03-09T18:52:00","date_gmt":"2018-03-09T09:52:00","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=357"},"modified":"2018-03-09T22:08:13","modified_gmt":"2018-03-09T13:08:13","slug":"%e5%bf%85%e8%a6%8b%ef%bc%81electron%e3%81%ae%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e5%ae%9f%e8%a1%8c%e3%81%a7%e6%b3%a8%e6%84%8f%e3%81%99%e3%81%b9%e3%81%8d%e7%82%b9","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=357","title":{"rendered":"\u5fc5\u898b\uff01Electron\u306e\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3067\u6ce8\u610f\u3059\u3079\u304d\u70b9"},"content":{"rendered":"<p>\u524d\u56de\u306e\u8a18\u4e8b\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=352\">\u4e00\u6c17\u306bWin,Mac,Linux\u306b\u30a2\u30d7\u30ea\u958b\u767a\uff01Electron\u3092\u89e6\u3063\u3066\u307f\u305f\u611f\u60f3\uff08\u30e1\u30ea\u30c3\u30c86\u3064\uff0f\u30c7\u30e1\u30ea\u30c3\u30c8\uff13\u3064<\/a>\uff09\u3067Electron\u306e\u30e1\u30ea\u30c3\u30c8\uff0f\u30c7\u30e1\u30ea\u30c3\u30c8\u3092\u307e\u3068\u3081\u3066\u307f\u305f\u308f\u3051\u3067\u3059\u3051\u3069\u3001\u3055\u3089\u306b\u958b\u767a\u304c\u9032\u3093\u3060\u7d50\u679c\u3068\u3057\u3066\u3001\u4e00\u3064\u6c17\u3092\u3064\u3051\u3066\u304a\u304b\u306a\u304b\u308c\u3070\u3044\u3051\u306a\u3044\u70b9\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u306f\u3001\u30ba\u30d0\u30ea\uff08Unix\uff09\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u304d\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u300cls\u300d\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u304d\u3001<b>child_process<\/b>\u306e<b>spawn()<\/b>\u306a\u3089\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre><b>const {spawn} = require('child_process');<\/b>\n\n<b>let command = 'ls';<\/b>\n<b>spawn('\/bin\/sh', ['-c', command]);<\/b><\/pre>\n<p><i>\u203b\u30b3\u30de\u30f3\u30c9\u3092\u305d\u306e\u307e\u307e\u30c6\u30ad\u30b9\u30c8\u3067\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u3001\u901a\u5e38\u3068\u306f\u5c11\u3057\u5909\u5f62\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3057\u3066\u307e\u3059\u3002<\/i><\/p>\n<p>\u3082\u3061\u308d\u3093\u3001\u300cls\u300d\u306f\u901a\u5e38\u306e\u30b3\u30de\u30f3\u30c9\u306a\u306e\u3067\u554f\u984c\u306f\u306a\u3044\u3093\u3067\u3059\u3051\u3069\u3001\u3053\u308c\u304c\u300cPython\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u300d\u3068\u306a\u308b\u3068\u5c11\u3057\u610f\u5473\u5408\u3044\u304c\u5909\u308f\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<p><b style=\"font-size: 35px;\">\u306a\u305c\u306a\u3089\u3001\u5b9f\u884c\u4e2d\u306bPython\u3092\u4e2d\u65ad\u3057\u3088\u3046\u3068\u3057\u3066\u3082kill\u3059\u308b\u305f\u3081\u306e\u300cpid\u300d\u304c\u898b\u3064\u304b\u3089\u305a\u3001\u6b62\u3081\u3089\u308c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3059\u3002\u30ab\u30c3\u30d1\u3048\u3073\u305b\u3093\u306e\u3088\u3046\u306b\u3002<\/b><\/p>\n<p>\u5143\u3005\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bspawn()\u306e\u8fd4\u308a\u5024\u306b\u3042\u308bkill()\u3092\u4f7f\u3048\u3070\u51e6\u7406\u3092\u6b62\u3081\u3066\u304f\u308c\u308b\u3093\u3067\u3059\u3051\u3069\u3001\u3053\u308c\u306f<span style=\"text-decoration: underline;\">\u30b7\u30a7\u30eb\u81ea\u8eab\u3092\u6b62\u3081\u308b\u3060\u3051\u3067\u3001Python\u306a\u3069\u5225\u30d7\u30ed\u30b0\u30e9\u30e0\u307e\u3067\u306f\u3081\u3093\u3069\u3046\u898b\u3066\u304f\u308c\u306a\u3044<\/span>\u3001\u3068\u3044\u3046\u3053\u3068\u306e\u3088\u3046\u3067\u3059\u3002\uff08\u3064\u307e\u308a\uff12\u3064\u30d7\u30ed\u30bb\u30b9\u304c\u8d70\u308b\uff09<\/p>\n<pre><b>let childProcess = spawn('\/bin\/sh', ['-c', 'python test.py']);<\/b>\n<b>childProcess.kill(); \/\/ \u3053\u3053\u3067python\u306f\u6b62\u307e\u3089\u306a\u3044<\/b><\/pre>\n<p>\u3058\u3083\u3042\u3001spawn()\u306e\u8fd4\u308a\u5024\u306e\u4e2d\u304b\u3089\u3001python\u306epid\u3092\u898b\u3064\u3051\u3066\u72ec\u81ea\u306b\u4e2d\u65ad\u3059\u308c\u3070\u3044\u3044\u30fb\u30fb\u30fb\u3068\u601d\u3044\u304d\u3084pid\u306f\u30b7\u30a7\u30eb\u81ea\u8eab\u306e\u3082\u306e\u3057\u304b\u898b\u3064\u304b\u3089\u305a\u3001python\u306e\u3082\u306e\u306f\u683c\u7d0d\u3055\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u3067\u3057\u305f\u3002<\/p>\n<p>\u3046\u30fc\u3093\u3001\u3069\u3046\u3057\u305f\u3082\u306e\u304b\u3002<\/p>\n<h1>\u3072\u3068\u3064\u306e\u89e3\u6c7a\u6cd5<\/h1>\n<p>\u8272\u3005\u3068\u8a66\u3057\u307e\u3057\u305f\u3051\u3069\u3001\u7d50\u5c40\u306f\u6ce5\u81ed\u304f\u300c<b>\u5168\u3066\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u4e2d\u304b\u3089\u8a72\u5f53\u3059\u308b\u3082\u306e\u3092\u691c\u7d22\u3057\u3066\u4e2d\u65ad\u3059\u308b<\/b>\u300d\u3068\u3044\u3046\u65b9\u6cd5\u3057\u304b\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u3068\u3057\u3066\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u300cps\u300d\u3068\u300cgrep\u300d\u3067\u4e2d\u65ad\u3057\u305f\u3044\u30d7\u30ed\u30bb\u30b9\u3092\u898b\u3064\u3051\u51fa\u3057\u3001process.kill()\u3092\u4f7f\u3063\u3066\u51e6\u7406\u3092\u4e2d\u65ad\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre><b>let command = 'ps -ef | grep \"python\" | grep \"test.py\" | awk \\'{print $2}\\'';<\/b>\n<b>let childProcess = spawn('\/bin\/sh', ['-c', command]);<\/b>\n<b>childProcess.stdout.on('data', (data) =&gt; {<\/b>\n<b>    let pidStr = `${data}`;<\/b>\n<b>    let pids = pidStr.split(\"\\n\");<\/b>\n<b>    pids.forEach((pid) =&gt; {<\/b>\n<b>        if(pid != '') {<\/b>\n<b>            try {<\/b>\n<b>                process.kill(pid);<\/b>\n<b>            } catch(e) {}<\/b>\n<b>        }<\/b>\n<b>    });<\/b>\n<b>});<\/b><\/pre>\n<p>\u3044\u307e\u306e\u3068\u3053\u308d\u306f\u3001\u3053\u308c\u3067\u3046\u307e\u304f\u3044\u3063\u3066\u307e\u3059\u3051\u3069\u3001\u3082\u3063\u3068\u30b9\u30de\u30fc\u30c8\u306a\u89e3\u6c7a\u6cd5\u304c\u3042\u308a\u305d\u3046\u306a\u6c17\u3082\u3057\u307e\u3059\u306d\u3002\u305f\u3060\u3001stack overflow\u3067\u3082\u300c\u30b3\u30ec\uff01\u300d\u3063\u3066\u3044\u3046\u6c7a\u3081\u624b\u306b\u306a\u308b\u3088\u3046\u306a\u89e3\u6c7a\u6cd5\u306f\u898b\u3064\u304b\u3089\u306a\u304b\u3063\u305f\u3067\u3059\u3057\u3001\u5f53\u5206\u306f\u3053\u306e\u65b9\u6cd5\u3067\u5bfe\u51e6\u3059\u308b\u3057\u304b\u306a\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u4f55\u304b\u3044\u3044\u30a2\u30a4\u30c7\u30a2\u304c\u3042\u3063\u305f\u3089\u6559\u3048\u3066\u304f\u3060\u3055\u3044\u3002m_ _m<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306e\u8a18\u4e8b\u3001\u4e00\u6c17\u306bWin,Mac,Linux\u306b\u30a2\u30d7\u30ea\u958b\u767a\uff01Electron\u3092\u89e6\u3063\u3066\u307f\u305f\u611f\u60f3\uff08\u30e1\u30ea\u30c3\u30c86\u3064\uff0f\u30c7\u30e1\u30ea\u30c3\u30c8\uff13\u3064\uff09\u3067Electron\u306e\u30e1\u30ea\u30c3\u30c8\uff0f\u30c7\u30e1\u30ea\u30c3 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=357\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u5fc5\u898b\uff01Electron\u306e\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3067\u6ce8\u610f\u3059\u3079\u304d\u70b9&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":355,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49,19],"tags":[50],"class_list":["post-357","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-electron","category-javascript","tag-50"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":3,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":363,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions\/363"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/355"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}