Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Minecraft/Node-写入process.stdin,子进程也接收输入_Node.js_Minecraft - Fatal编程技术网

Node.js Minecraft/Node-写入process.stdin,子进程也接收输入

Node.js Minecraft/Node-写入process.stdin,子进程也接收输入,node.js,minecraft,Node.js,Minecraft,我正在尝试编写一个终端应用程序,允许我启动和停止Minecraft服务器,通过readline写入参数,该参数首先由节点进程检查,然后,如果脚本确定,则发送到Minecraft服务器以供使用 使用最新的节点构建和Minecraft JE服务器在Windows 10上运行 首先,我测试了如何启动一个节点进程,该节点进程是在一个子进程中生成的,该子进程包含Minecraft服务器。我将3个stdio参数设置为“inherit”和“ipc”(不是100%确定为什么需要这样做,但我看到其他人这样做)。一

我正在尝试编写一个终端应用程序,允许我启动和停止Minecraft服务器,通过readline写入参数,该参数首先由节点进程检查,然后,如果脚本确定,则发送到Minecraft服务器以供使用

使用最新的节点构建和Minecraft JE服务器在Windows 10上运行

首先,我测试了如何启动一个节点进程,该节点进程是在一个子进程中生成的,该子进程包含Minecraft服务器。我将3个stdio参数设置为“inherit”和“ipc”(不是100%确定为什么需要这样做,但我看到其他人这样做)。一旦运行,如果我在终端中键入任何内容,Minecraft服务器将通过节点接收输入。这太棒了。不过,我想要的是能够运行readline和解析输入,并确定节点是否应该处理输入,或者是否应该将输入发送到Minecraft服务器

因此,我使用stdio参数并使用process.stdin.write()等,试图找出如何写入子进程的stdin,以便Minecraft服务器接收输入,但没有效果

因此,我尝试运行一个“主”节点进程,它将派生一个辅助节点进程。“master”将运行readline,如果要将任何输入发送到那里,则使用child.send()。然后,在第二个节点过程中,我将启动Minecraft服务器作为一个派生,并将所有3个stdio参数设置为继承。然后,我将使用process.on('message')进行侦听,如果收到消息,则将其写入process.stdin,希望Minecraft进程通过继承的输入接收它。但这也不起作用

我尝试过很多不同的事情,但最后我没有任何运气。我试着尽可能多地查找,但我没有找到任何有助于我解决问题的方法。对不起,如果这是一个没有大脑的结果

// First Iteration
// spawns in a minecraft server and listens for input in the terminal
// effectively the same as running the equivalent run command for the minecraft server, except this runs as a Node child process

const spawn = require('child_process').spawn
var minecraft = spawn('java',  ['-jar', '-Xms1G','-Xmx1G', '-Dfile.encoding=utf8', '../spigot-1.13.2.jar'], {
    stdio: [
        'inherit',
        'inherit',
        'inherit',
        'ipc'
    ],
})


// Second Iteration
// changed cp stdin to pipe and tried to write manually via rl

const spawn = require('child_process').spawn
const readline = require('readline')
var minecraft = spawn('java',  ['-jar', '-Xms1G','-Xmx1G', '-Dfile.encoding=utf8', '../spigot-1.13.2.jar'], {
    stdio: [
        'pipe',
        'inherit',
        'inherit',
        'ipc'
    ],
})
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
}).on('line',(line)=> {
    process.stdin.write(line)
})


// Later iterations involved running nested child processes, basically, but were all more or less more-abstract versions of my second iteration.
正如我前面所说,我想要实现的是能够通过readline从终端监听管理员输入,并在适当的情况下将该输入发送到Minecraft服务器进程。否则,readline输入将在节点进程中处理


**澄清一下,当我说它不起作用时,我的意思是我没有得到来自Minecraft服务器进程的响应。游戏中没有,命令行上也没有。在我的第一次迭代中,我可以在游戏中和命令行上看到Minecraft进程的输出。但是到第二次迭代时,什么都没有。

您无法写入
进程.stdin
。你是想写入minecraft进程的stdin
mincraft.stdin

minecraft.stdin.write(line)

无法写入
进程.stdin
。你是想写入minecraft进程的stdin
mincraft.stdin

minecraft.stdin.write(line)
当我输入“test”时,这个脚本会给我一些提示。当我输入“test”时,这个脚本会给我一些提示。