Reputation: 101
I want to write a python script which can launch an application.The application being launched can also read python commands which I am passing through another script. The problem I am facing is that I need to use two python scripts, one to launch an application and second one to run commands in launched application. Can I achieve this using a single script? How do I tell python to run next few lines of script in launched application?
Upvotes: 0
Views: 723
Reputation: 401
In general, you use subprocess.Popen
to launch a command from python. If you set it as non-blocking, it'll let you keep running python statements. You also have access to the running subprocesses stdin and stdout so you can interact with the running application.
If I understand what you're asking, it'd look something like this:
import subprocess
app = subprocess.Popen(["/path/to/app", "-and", "args"], stdin=subprocess.PIPE)
app.stdin.write("python command\n")
Upvotes: 3