Redirect the standard input and output of .net program
I a开发者_如何学运维m writing a test script for a C/S system in python. And right now, we only have a test client written in C#. It is a command line based client. I want to control the input and get the output of the client in my python script. How could I make it?
Thanks!
Use the subprocess
module as follows:
import subprocess
proc = subprocess.Popen("cat", stdin = subprocess.PIPE, stdout = subprocess.PIPE)
out, err = proc.communicate(input)
The process ends after the last call. If you want to do some input iteratively, you can use proc.stdin.write
, but you have to call communicate(None)
at the end to finish the process.
Use subprocess.Popen
.
精彩评论