0

So what I'm making right now is a Minecraft controller that can be controlled through Node.js. I have the server hosted on my local machine so I can run commands through a command prompt. I have the command prompt down, but how can I run the command prompt, and keep it open for later use so I can run commands after its started up?

I found 1 questions, but both answers don't meet my needs, because in this one (Keep CMD open after BAT file executes) it has it so you can look at any errors or what it did after it started. I also think it has something to do with child_process, and I looked at the Node.js documentary for child_process (https://nodejs.org/api/child_process.html) but I don't understand it too well.

Toasty
  • 722
  • 1
  • 18
Grayseon
  • 1
  • 1
  • 1
    The post you linked works the same for your needs as it did for the post there. Did you try what the answer to that question says? – Ken White Apr 12 '21 at 21:11
  • Does this answer your question? [Keep CMD open after BAT file executes](https://stackoverflow.com/questions/17957076/keep-cmd-open-after-bat-file-executes) – Ken White Apr 12 '21 at 21:12
  • Thanks for the help, but I'm looking for something where I can run commands in it after the file is executed. For example, the .bat file creates a text file, and 3 seconds later Node.js tells the .bat file to write something in it. (Its just an example, I know about fs.) – Grayseon Apr 13 '21 at 02:39
  • That's not going to happen. You can't do this with a batch file. You can do it with code that opens a console window using the WinAPI, but not from a batch file. – Ken White Apr 13 '21 at 03:03
  • Hi, I got some help and got the solution. First you start the bat process with childprocess.exec() and you save it into a variable like `var child = childprocess.exec(command)`. Then to execute something in it you have to do `child.stdin.write(command\n)` The `\n` is very important because it enters it. – Grayseon Apr 14 '21 at 23:31

0 Answers0