By example, have a simple pipe on python 3:
processHandler = subprocess.Popen(
[ 'git-receive-pack', '/tmp/repo.git' ],
stdin=sys.stdin,
stdout=sys.stdout
)
processHandler.communicate()
processHandler.wait()
The python script replace the original git-receive-pack
command (from ssh) and python script call to git-receive-pack
with a simple pipe. This works fine, but, need detect the commit data, by example: the branch, actions (commit, merge, etc).
The communication is not always separated with newlines and the data transfer can be in both ways, so I cannot do a while to get the whole request and then send it to the execution of the command since there can be more than one request and more than one answer, so the use of pipe is required.
Have two problems: 1. I don't know the plaintext protocol that is transferred between the client and the server application, so I don't know how to create a regular expression that takes these values. 2. I cannot intercept the input and output data of the process because the pipes of the same system are established, if I redirect stdout
to a file then it will not be able to send the response bytes to the client.
How can I intercept the sys.stdin
and sys.stdout
without affecting the pipe between python and git?