2016-12-05 211 views
0

我正在構建一個小工具,應該讓我啓動一個Tomcat服務器。電子打開並保持打開cmd.exe

很容易,我只是想要一個按鈕來啓動startup.bat和另一個調用shutdown.bat

它工作得很好(服務器啓動和停止),但完全在忍者模式下,我無法設法使用日誌獲取Tomcat控制檯。 如果我打電話給startup.bat,可以從經典命令行打開一個窗口,其中包含日誌。 我試過exec,execFile,spawn。我試着直接撥打batcmd.exe,甚至試過start。但我無法獲得該窗口。

我知道我可以得到流,但我不想打擾。

此外,我只是在Windows上使用該工具,現在不需要考慮其他平臺。

const ipc = require('electron').ipcMain; 
const execFile = require('child_process').execFile; 

ipc.on('start-local-tomcat', function (event) { 
    execFile('cmd.exe', ['D:\\DEV\\apache-tomcat-8.0.12\\bin\\startup.bat'], 
    {env: {'CATALINA_HOME': 'D:\\DEV\\apache-tomcat-8.0.12'}}, 
    function (error, stdout, stderr) { 
     console.log('stdout: ' + stdout); 
     console.log('stderr: ' + stderr); 
     if (error !== null) { 
     console.log('exec error: ' + error); 
     } 
    }) 
}); 

ipc.on('stop-local-tomcat', function (event) { 
    execFile('cmd.exe',['D:\\DEV\\apache-tomcat-8.0.12\\bin\\shutdown.bat'], 
    {env: {'CATALINA_HOME': 'D:\\DEV\\apache-tomcat-8.0.12'}}, 
    function (error, stdout, stderr) { 
     console.log('stdout: ' + stdout); 
     console.log('stderr: ' + stderr); 
     if (error !== null) { 
     console.log('exec error: ' + error); 
     } 
    }) 
}); 

回答

0

最後我只是沒有讀文檔不夠,還有一個名爲detached參數,將盡正是我想要的:

var child = spawn(
    'D:\\DEV\\apache-tomcat-8.0.12\\bin\\startup.bat', 
    { 
     env: {'CATALINA_HOME': 'D:\\DEV\\apache-tomcat-8.0.12'}, 
     detached: true 
    } 
);