【问题标题】:Sending response after file changes文件更改后发送响应
【发布时间】:2017-08-12 16:35:14
【问题描述】:

我想在 matlab 中使用 shelljs 执行命令,并在完成向客户端发送响应后:

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

我不知道如何获得响应,所以我让 matlab 用 Code (Ok, Fail) 更改了一个文件并使用 fswatch 观察它,我的目标是更改后发送 200 状态,但在使用 Postman 测试时抛出错误。

  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');
    }
});

我知道这似乎不是一个好方法,但任何帮助

【问题讨论】:

    标签: fswatch shelljs


    【解决方案1】:

    我通过承诺 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');
              } 
            }
          }));
    

    【讨论】:

      猜你喜欢
      • 2021-01-18
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      相关资源
      最近更新 更多