Jump to content

NodeJS exec() shell

Hi.

 

I am a small part of a Discord bot that has Minecraft-server-console-logging-in-a-discord-channel functionality. We currently use NodeJS' 

child_process.exec(command[, options][, callback])

which creates a shell and runs a command in it (in our case it is a start Minecraft server command). We then pass its STDOUT to a discord channel. I am looking for a way where whatever we type into that channel will be executed in the virtual shell that the Minecraft server is in. 

 

Thanks!

Edited by IAmAFrenchFry
Finished the message
Link to comment
Share on other sites

Link to post
Share on other sites

If you start the process using child_process.spawn rather than child_process.exec, it's a lot more powerful, although also a bit less user friendly. In particular, it provides a ChildProcess object, on which you can call childProcess.stdin.write("myData");

 

For example, you could do

const process = child_process.spawn("command", ["-arg1", "-arg2"]);

someEventProducer.on("userSentSomething", (input) => process.stdin.write(input));

This is equivalent to typing into the terminal if you ran the server manually.

 

If you go down this route, you probably need more error handling, etc, but hopefully this sets you in the right direction.

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×