0

I have a linux console application which behaves in a similar way to bash in that it receives commands while it's running in the same way and I want to use it via Python (use python to send inputs and receive outputs to/from the application while it’s running).

The application in question is custom Minecraft server software, it does not appear to have a useable API/SDK for my needs

How would I be able to run it, capture its output and interact with it (Enter commands into the program) using Python code.

Bluebot
  • 166
  • 15

1 Answers1

0

You can use os.sytem(command) to just run a command, or if you want the output then try subprocess.check_output(commands), which returns whatever is returned by bash. Pass a list of commands to this, for example, to run node index.js, you'd pass ["node", "index.js"]

pjones123
  • 355
  • 2
  • 7
  • Yes, but how would I interact with it, sorry if not clear – Bluebot Nov 11 '20 at 19:06
  • what do you mean by that that isn't covered by my answer? – pjones123 Nov 12 '20 at 15:32
  • I don't understand how to pass commands while the program is running, it's a little bit like bash in which you can run commands in a similar way for example, the server software has a 'help' command and I would run it by first: running the server, then, in the shell that I ran the server in I would type 'help' – Bluebot Nov 13 '20 at 07:11
  • Your code would allow me to add arguments to the command, however, I do not believe it would be able to allow me to run commands/give inputs to the command application whilst it is running – Bluebot Nov 13 '20 at 08:18
  • 1
    yes I believe you are right, in which case I don't have an answer for you, sorry. However, this might cover your issue: https://stackoverflow.com/questions/1124884/interact-with-a-windows-console-application-via-python – pjones123 Nov 14 '20 at 19:21