CNode

nodejs exec问题

Jjunxing1025发布于13 年前最后回复13 年前5 回复22786 浏览0 收藏

我使用sudo node运行node代码, 运行到 var exec = require('child_process').exec; cmd = '/home/usr/script/setup.sh' exec(cmd, function callback(error, stdout, stderr) { console.log(stdout);
}); 运行不下去,但是我直接在终端运行cmd就可以,为什么啊,求助

查看回复

回复 (5)

H
hexie#1·13 年前

console.log(error, stdout,stderr);

全部打印出来看看

J
junxing1025#2·13 年前
引用 hexieconsole.log(error, stdout,stderr); 全部打印出来看看
  1. 打印出来就是没有运行成功,我估计可能是因为脚本的原因

  2. 我使用了expect 提示没有连接成功 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the RSA key sent by the remote host is 8f:7a:50:a5:0a:4c:cf:cd:51:55:2a:80:2d:35:7e:b7. Please contact your system administrator. Add correct host key in /root/.ssh/known_hosts to get rid of this message. Offending RSA key in /root/.ssh/known_hosts:1 remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.1.1 RSA host key for 192.168.1.1 has changed and you have requested strict checking. Host key verification failed. lost connection

  3. 运行node不使用sudo 就可以运行成功

M
mq1980#3·13 年前

怎么感觉是你的sh文件的问题呢? 你试试 使用sodo /home/usr/script/setup.sh 看能不能执行

M
mq1980#5·13 年前

Add correct host key in /root/.ssh/known_hosts to get rid of this message. Offending RSA key in /root/.ssh/known_hosts:1 remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.1.1 RSA host key for 192.168.1.1 has changed and you have requested strict checking. Host key verification failed.

看你异常里说明,sodo命令会使用root权限执行程序 并且使用root的环境配置,估计你的登录用户和root用户在ssh处的配置不同 检查下吧

参与回复
登录后即可参与回复。登录