![](/img/trans.png)
[英]Child process spawn is producing TypeError “stdout.on is not a function” in Electron
[英]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)
我的版本是:
在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.