Python subprocess .check_call vs .check_output

Viewed 54310

My python script (python 3.4.3) calls a bash script via subprocess:

import subprocess as sp
res = sp.check_output("bashscript", shell=True)

The bashscript contains the following line:

ssh -MNf somehost

which opens a shared master connection to some remote host to allow some subsequent operations.

When executing the python script, it will prompt for password for the ssh line but then it blocks after the password is entered and never returns. When I ctrl-C to terminate the script, I see that the connection was properly established (so ssh line was successfully executed).

I don't have this blocking problem when using check_call instead of check_output, but check_call does not retrieve stdout. I'd like to understand what exactly is causing the blocking behavior for check_output, probably related to some subtlety with ssh -MNf.

1 Answers
Related