electronでクライアントアプリを作成してその中でexeファイルを実行したいのですが、main.jsのカレントディレクトリに実行するexeが入っているにも関わらずopenできないエラーにあっています。
またデザイン面以外のjavascriptはwindowを作るmain.jsに記述するのが正しいのかも分かりません。
以下がコードになります。
javascript
1const {app, Menu, BrowserWindow} = require('electron'); 2const {exec, execFile} = require('child-process-promise'); 3const kill=require('tree-kill'); 4const APP_NAME = new Array('./src/test.exe'); 5let pid =new Array(); 6let mainWindow; 7let i =0; 8 9function createWindow(){ 10 mainWindow = new BrowserWindow({width:400,height:600,'icon': __dirname+'/src/REIAcat.ico',}); 11 mainWindow.loadFile("./index.html"); 12 Menu.setApplicationMenu(null); 13 if(process.env.NODE_EV=="debug") 14 mainWindow.webContents.openDevTools(); 15 mainWindow.on("closed",function(){ 16 mainWindow=null; 17 }); 18} 19app.on("ready",function(){ 20 //window逕滓・ 21 createWindow(); 22 //socket繧「繝励Μ襍キ蜍・ 23 // while(i < APP_NAME.length){ 24 execFile('open',[APP_NAME[i]]) 25 .then(_=>`powershell -command "Get-WmiObject win32_process | select processid, name | Where-Object {$_.name -match \"${APP_NAME[i]}\"} | select processid >> temp.txt ; (Get-Content \"temp.txt\")[3] ; del temp.txt"`) 26 .then((result)=>{ 27 if(result.stderr){ 28 throw(result.stderr); 29 } 30 pid.push(parseInt(result.stdout)); 31 logger.debug(`START AppName ${APP_NAME[i]},pid:${pid[i]}`); 32 i++; 33 34 }).catch((err)=>{ 35 logger.debug(`Error:${JSON.stringify(err)}`); 36 }); 37 38 // exec.then=then(function(){ 39 // exec(`powershell -command "Get-WmiObject win32_process | select processid, name | Where-Object {$_.name -match \"${APP_NAME[i]}\"} | select processid >> temp.txt ; (Get-Content \"temp.txt\")[3] ; del temp.txt"`, 40 // function(err,stdout,stderr){ 41 // if(err){ 42 // throw err; 43 // } 44 // }); 45 // }); 46 47 48 // } 49 50}); 51app.on("window-all-closed",function(){ 52 if(process.platform !== 'darwin'){ 53 i=0; 54 while(i <pid.length){ 55 kill(pid[i]); 56 i++; 57 } 58 app.quit() 59 } 60}); 61app.on("activate",function(){ 62 if(mainWindow===null) 63 createWindow(); 64 65});
child-promiseで起動してコマンドを使ってpidを取得しcloseWindowするときにkillするだけなのですが、
なぜかopenしてくれないという状況になっています。
わかる方がいれば教えていただけるとありがたいです。
回答よろしくお願いします。
エラー内容:
error
1{ ChildProcessError: spawn open ENOENT `open ./src/test.exe` (exited with error code ENOENT) 2 at callback (C:\Users\userName\Downloads\learn_c\socket\node_modules\child-process-promise\lib\index.js:33:27) 3at exithandler (child_process.js:306:5) 4at ChildProcess.errorhandler (child_process.js:318:5) 5at ChildProcess.emit (events.js:182:13) 6at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12) 7at onErrorNT (internal/child_process.js:407:16) 8at process._tickCallback (internal/process/next_tick.js:63:19) 9 name: 'ChildProcessError', code: 'ENOENT', childProcess: { ChildProcess: { [Function: ChildProcess] super_: [Function] }, 10fork: [Function: fork], 11 _forkChild: [Function: _forkChild], 12 exec: { [Function] [Symbol(util.promisify.custom)]: [Function] }, 13 execFile: { [Function] [Symbol(util.promisify.custom)]: [Function] }, 14 spawn: [Function: spawn], 15 spawnSync: [Function: spawnSync], 16 execFileSync: [Function], 17execSync: [Function] }, 18stdout: '', 19 stderr: '' } 20
あなたの回答
tips
プレビュー