簡體   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