使用node.js(childProcess)运行shell脚本 [英] Run shell script with node.js (childProcess)

查看:253
本文介绍了使用node.js(childProcess)运行shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的node.js服务器上运行一个shell脚本,但没有发生任何事情。

  childProcess.exec ('〜/./ play.sh / media / external /'+ req.params.movi​​e,function(){}); //不工作

另一个childProcess是完美的,但上面的过程不会。

  childProcess.exec('ls / media / external /',movieCallback); //工作

如果我在终端中运行脚本,那么它的工作原理。有任何想法吗? (chmod + x设置)

解决方案

exec函数回调有错误,stdout和stderr参数传递给它。看看他们是否可以通过将其分发到控制台来帮助您诊断问题:

  exec('〜/./ play。 sh / media / external /'+ req.params.movi​​e,
function(error,stdout,stderr){
console.log('stdout:'+ stdout);
console.log ('stderr:'+ stderr);
if(error!== null){
console.log('exec error:'+ error);
}
}) ;


I want to run a shell script on my node.js server, but nothing happened...

childProcess.exec('~/./play.sh /media/external/' + req.params.movie, function() {}); //not working

Another childProcess works perfect, but the process above won't.

childProcess.exec('ls /media/external/', movieCallback); //works

If I run the script in terminal, then it works. Any ideas? (chmod +x is set)

解决方案

The exec function callback has error, stdout and stderr arguments passed to it. See if they can help you diagnose the problem by spitting them out to the console:

exec('~/./play.sh /media/external/' + req.params.movie,
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
});

这篇关于使用node.js(childProcess)运行shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆