manage.js 897 B

123456789101112131415161718192021222324252627
  1. const config = require('./config');
  2. const child_process = require('child_process');
  3. var os = require('os');
  4. config.servers.forEach((host, index) => {
  5. var cmd;
  6. if (os.platform() == 'darwin') {
  7. var cmd = [
  8. 'osascript -e \'tell application "Terminal" to activate\' ',
  9. '-e \'tell application "System Events" to tell process "Terminal" to keystroke "t"',
  10. "using command down' ",
  11. '-e \'tell application "Terminal" to do script',
  12. '"',
  13. `cd ${__dirname} && node server.js ${host} ${index}`,
  14. '"',
  15. "in selected tab of the front window'",
  16. ].join('');
  17. } else {
  18. cmd = `start cmd.exe /K "cd /d ${__dirname} && node server.js ${host} ${index}"`;
  19. }
  20. var child = child_process.exec(cmd);
  21. child.on('exit', function(code) {
  22. console.log('child exit');
  23. });
  24. });