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

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

问题描述

我想在我的 node.js 服务器上运行一个 shell 脚本,但是什么也没发生...

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

另一个 childProcess 工作完美,但上面的过程不会.

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

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

如果我在终端中运行脚本,那么它就可以工作.有任何想法吗?(chmod +x 设置)

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

推荐答案

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

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天全站免登陆