0

For now i have some Command-Line Interface which one i need to interact. (e.g. run this CLI in terminal, then execute few comands inside of it). In terminal it looks the next way:

blabla-cli
some-comand
%response%
next-command

And all of it i want to automate with python.

Almost all what i could fing in the Google is about using Popen and comunicate or process.stdin to do what i want. But in case of using provided code i can't send any comand to process, i mean "help" wont be sended to terminal

args = ["blabla-cli"]
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
process.wait()
process.stdin.writelines('help')
process.wait()
print(process.stdout.readlines())

I expect to send some command to terminal via python code, get some response and get some actions with recieved response.

furas
  • 134,197
  • 12
  • 106
  • 148
SpaceBucks
  • 25
  • 2
  • Maybe this can be of help: https://stackoverflow.com/questions/2804543/read-subprocess-stdout-line-by-line –  Jul 28 '19 at 13:01
  • do you get error ?always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Jul 28 '19 at 13:29
  • `writelines` means list with many lines - not single string. If you use string then it will treat every char as single line. – furas Jul 28 '19 at 13:31

0 Answers0