Note that there are some explanatory texts on larger screens.

plurals
  1. POPersistent ssh session in Python using Popen
    primarykey
    data
    text
    <p>I am creating a movie controller (Pause/Stop...) using python where I ssh into a remote computer, and issue commands into a named pipe like so</p> <pre><code>echo -n q &gt; ~/pipes/pipename </code></pre> <p>I know this works if I ssh via the terminal and do it myself, so there is no problem with the setup of the named pipe redirection. My problem is that setting up an ssh session takes time (1-3 seconds), whereas I want the pause command to be instantaneous. Therefore, I thought of setting up a persistent pipe like so:</p> <pre><code>controller = subprocess.Popen ( "ssh -T -x &lt;hostname&gt;", shell = True, close_fds = True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE ) </code></pre> <p>Then issue commands to it like so</p> <pre><code>controller.stdin.write ( 'echo -n q &gt; ~/pipes/pipename' ) </code></pre> <p>I think the problem is that <code>ssh</code> is interactive so it expects a carriage return. This is where my problems begin, as nearly everyone who has asked this question has been told to use an existing module:</p> <ul> <li><a href="https://stackoverflow.com/a/10684894/654789">Vivek's answer</a></li> <li><a href="https://stackoverflow.com/a/15776329/654789">Chakib's Answer</a></li> <li><a href="https://stackoverflow.com/a/15772823/654789">shx2's Answer</a></li> <li><a href="https://stackoverflow.com/a/15167643/654789">Crafty Thumber's Answer</a></li> <li><a href="https://stackoverflow.com/a/14996859/654789">Artyom's Answer</a></li> <li><a href="https://stackoverflow.com/a/1233808/654789">Jon W's Answer</a></li> </ul> <p>Which is fine, but I am so close. I just need to know how to include the carriage return, otherwise, I have to go learn all these other modules, which mind you is not trivial (for example, right now I can't figure out how pexpect uses either my <code>/etc/hosts</code> file or my ssh keyless authentications).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload