Interacting with another command line program in Python

后端 未结 2 1724
轮回少年
轮回少年 2021-02-02 02:55

I need to write a Python script that can run another command line program and interact with it\'s stdin and stdout streams. Essentially, the Python script will read from the tar

2条回答
  •  粉色の甜心
    2021-02-02 03:26

    see the question wxPython: how to create a bash shell window?

    there I have given a full fledged interaction with bash shell reading stdout and stderr and communicating via stdin

    main part is extension of this code

    bp = Popen('bash', shell=False, stdout=PIPE, stdin=PIPE, stderr=PIPE)
    bp.stdin.write("ls\n")
    bp.stdout.readline()
    

    if we read all data it will get blocked so the link to script I have given does it in a thread. That is a complete wxpython app mimicking bash shell partially.

提交回复
热议问题