Executing multiple commands using Popen.stdin

前端 未结 4 1395
醉酒成梦
醉酒成梦 2021-02-07 04:58

I\'d like to execute multiple commands in a standalone application launched from a python script, using pipes. The only way I could reliably pass the commands to the stdin of th

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 05:16

    It sounds like your application is treating input from a pipe in a strange way. This means it won't get all of the commands you send until you close the pipe.

    So the approach I would suggest is just to do this:

    process.stdin.write("command1\n")
    process.stdin.write("command2\n")
    process.stdin.write("command3\n")
    process.stdin.close()
    

    It doesn't sound like your Python program is reading output from the application, so it shouldn't matter if you send the commands all at once like that.

提交回复
热议问题