繁体   English   中英

节点子进程产生“类型错误:错误的参数类型错误”?

[英]Node Child Process Spawn "TypeError: Bad argument TypeError"?

当我使用节点运行以下代码时:

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
  • 快速版本:4.12.0

Linux x64运行

该文件的权限为 755:

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

我以root身份运行。

关于可能导致此错误的任何想法? 奇怪的是我认为它以前有效......

这是一个愚蠢的答案... "command" was undefined 原因如下:

我的循环顶部有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
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM