2017-08-12 77 views
2

我想用shelljsMATLAB執行COMMANDE並完成後發送響應客戶端:發送響應變化

var cmd = 'matlab -nojvm -nosplash -nodesktop -noFigureWindows -minimize -r \" senario(); exit; \"'; 
    shell.exec(cmd, function (code, stdout, stderr) { 
      console.log('matlab exit'); 
     }); 

我不知道怎麼弄所以我做了matlab的響應改變一個文件與代碼(好,失敗),並觀看它使用fswatch,我的目標是改變後發送200狀態,但它是拋出一個錯誤,而testin克與郵差。

fs.watch("done.json", function (event, filename) { 
    console.log(filename + ' file Changed ...'); 
     return res.status(200); // I want to Add the response here 
    if (filename) { 
     console.log('filename provided: ' + filename); 
    } else { 
     console.log('filename not provided'); 
    } 
}); 

我知道,好像不

回答

1

我已經promisifying fs.watch

var Promise = require('bluebird'); 
var cmd = ['matlab -nojvm -nosplash -nodesktop -noFigureWindows -minimize -r \" addpath(genpath(\''+ __dirname+'\\..\\uploads\')); '+ nameSenarioToExe+'(); exit; \"'];/// 
    shell.exec(cmd, function (code, stdout, stderr) { 
      console.log('matlab exit'); 
     }); 
    var p = Promise.resolve(DistDir) 
    .timeout(2000) 
    .catch(console.error.bind(console, 'Failed to load config!')) 
    .then(fs.watch(filedir, function(event, who) { 
     if (event === 'rename' && who === filename) { 
      if (fs.existsSync(filedir)) { 
      res.send('OK'); 
      } 
     } 
     })); 
解決這一問題的好辦法,這樣做的,但任何幫助