node.js - 你能从 expressjs 应用程序调用 shell 脚本吗?

标签 node.js shell express

有谁知道是否可以从 expressjs 应用调用 shell 脚本?

我正在编写一个应用程序,我想在 git post-receive 钩子(Hook)之后移动一些文件,但在这部分遇到了困难。

最佳答案

是的!由于 Express 只是 Node ,您可以像这样使用 exec 执行您的服务器允许的任何命令:

var exec = require('child_process').exec;

function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("ls -la", function(error, stdout, stderr) {
  if (!error) {
    // things worked!
  } else {
    // things failed :(
  }
});

关于node.js - 你能从 expressjs 应用程序调用 shell 脚本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26806247/

相关文章:

javascript - 在 Node js 路由中发出 http 请求

javascript - 在 nodejs 中,如果记录不存在,如何将其插入到 PostgreSQL 中?

linux - hp-unix 中的 shell/sbin/sh 是哪个?

mysql - node.js/express/mysql/serialport/socket.io

node.js - 在 GraphQL Schema 中定义 map 对象的最佳方式?

javascript - Node.js API 对于同一请求返回不同的值

linux - 在 while 循环中使用 SSH 丢失属性值

linux - 如何让 Linux shell 命令堆栈只存储唯一的命令

javascript - 使voiceXML读取服务器返回的结果

node.js - jspdf 模块每次都会崩溃,并出现 ReferenceError : window is not defined