1

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?

e-info128
  • 3,727
  • 10
  • 40
  • 57
  • Does this answer your question? [How do I pass a string into subprocess.Popen (using the stdin argument)?](https://stackoverflow.com/questions/163542/how-do-i-pass-a-string-into-subprocess-popen-using-the-stdin-argument) – LeGEC Nov 28 '20 at 21:33
  • No, in the answers use a custom pipe, but not a system piped (by example netween ssh bash shell and git command). When use manualy pipe un git need interprete all protocol or process each by each byte. With a native system piped the request and response is transparent, but need logging this data. – e-info128 Nov 29 '20 at 04:28

0 Answers0