0

I am trying to write a script to open a third-party console application and run commands on Windows. The third-party console requires the two commands; 'connect' and 'run'. A typical input/output is shown below. This connects to the host server then runs a process indexed by three parameters (p1,p2,p3).

>connect server
Successfully connected to service.
>run p1 p2 p3
Successfully started.
FINISHED

The app does not allow me to execute both commands in one line using & as with cmd.

Despite reading the subprocess documentation I can't figure out how to pass my two commands into the executable.

I am using Python 3.5, so I believe subprocess.run should be suitable for this task. The snippet below simply opens the third-party console. I have tried other code, linked at the bottom of the post, but I am unsure how to implement it for my purpose.

import subprocess
exe = r'C:\...\third_party_app.exe'
subprocess.run(exe)

Below are some of the SO resources that could be helpful that I have tried, and failed, to interpret.

https://stackoverflow.com/tags/subprocess/info

Python - How do I pass a string into subprocess.Popen (using the stdin argument)?

Jan Zerebecki
  • 825
  • 7
  • 18
Necessary
  • 11
  • 2
  • read documents of signal module.. you should send signal and talk with your third party console ... – DRPK Nov 13 '17 at 13:13
  • It will depend on the third-part console and what APIs are available. For example, the Win32 API include functions like these: https://learn.microsoft.com/en-us/windows/console/console-functions – cdarke Nov 13 '17 at 13:36
  • Generally a console is not designed to be driven by another program but by keyboard input. I have to wonder why you need to drive a console and if there is a programatic way of executing the commands you need. – cdarke Nov 13 '17 at 13:39

0 Answers0