Custom standard input for python subprocess

I start the SSH process as follows:

sshproc = subprocess.Popen([command], shell=True) exit = os.waitpid(sshproc.pid, 0)[1] 

This works and opens an interactive terminal. Based on the documentation for subprocess , sshproc uses the sys.stdin script.

Question: how can I print in stderr or a file, what input goes into this child process? I am creating a logging API and am currently losing my ability to record which commands run in this SSH session.

I don't need an answer, just a push in the right direction.

Thanks everyone!

EDIT: It is important that I start the process as shown above so that I have an interactive SSH session with my user. For example. As far as I know, I can not use communicate() .

+2
python subprocess stdin
Sep 16 '10 at 17:56
source share
1 answer
 sshproc = subprocess.Popen([command], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) stdout_value, stderr_value = sshproc.communicate('through stdin to stdout') print repr(stdout_value) print repr(stderr_value) 

And, since you said you were pushing in the right direction, I thought I should point you to good readings:

-

+7
Sep 16 '10 at 18:19
source share



All Articles