节点subprocess派生“types错误:错误的types错误”?

当我运行下面的代码与节点:

var command = "/home/myScript.sh"; fs.exists(command, function(exists){ if(exists) { var childProcess = spawn(command, []); //this is line 602 } }); 

我得到这个错误:

 [critical error]: TypeError: Bad argument TypeError: Bad argument at TypeError (native) at ChildProcess.spawn (internal/child_process.js:274:26) at exports.spawn (child_process.js:362:9) at /home/simulations/GUIServer/Server/SocketServer.js:602:28 at FSReqWrap.cb [as oncomplete] (fs.js:212:19) TypeError: Bad argument at TypeError (native) at ChildProcess.spawn (internal/child_process.js:274:26) at exports.spawn (child_process.js:362:9) at /home/simulations/GUIServer/Server/SocketServer.js:602:28 at FSReqWrap.cb [as oncomplete] (fs.js:212:19) 

我的版本是:

  • 节点版本:v4.2.6
  • Express版本:4.12.0

Linux x64运行

该文件的权限是755:

 -rwxr-xr-x 1 root root 2502 2016-12-06 17:12 myScript.sh 

我以root身份运行。

任何想法可能导致这个错误? 有什么奇怪的是我认为它以前工作…

这是一个愚蠢的答案… “命令”是未定义的 。 原因如下:

我在我的循环的顶部有var command ,然后我试图在以后重新定义command 。 这是以某种方式导致command未定义。 以下是我正在做的事情:

错误

 var command = "/home/myScript.sh"; fs.exists(command, function(exists){ if(exists) { //"command" here is UNDEFINED!? var childProcess = spawn(command, []); }else { var command = "something new"; //THIS IS WHAT CAUSED THE PROBLEM } }); 

 var command = "/home/myScript.sh"; fs.exists(command, function(exists){ if(exists) { var childProcess = spawn(command, []); }else { command = "something new"; //FIXED } });