Python pexpect scripts run without error,but there are no outputs in output file
<p>I want to put the results of 'ls /home' into mylog1.txt through ssh.So,I can check it on my computer.When I run the script,there is no error,there is no output in mylog1.txtã</p>

<blockquote>
<pre><code>#!/usr/bin/env python
import pexpect
import sys

child=pexpect.spawn('ssh shiyanlou@192.168.42.2')
fout=file('mylog1.txt','w')
child.logfile=fout

child.expect("password:")
child.sendline("xxxxx")
child.expect('$')
child.sendline('ls /home')
</code></pre>
</blockquote>

<pre><code>shiyanlou:pythontest/ $ cat mylog1.txt                                                                                    
shiyanlou@192.168.42.2's password: xxxxxxx 
ls /home
</code></pre>

<p>There are just tow commands in the mylog1.txt file.Why?</p>

<p>pexpect is good to intereact with an application.</p>

<p>But if you simply want ssh and execute some command, i will advice you to try out <a href="http://www.paramiko.org/" rel="nofollow">Paramiko</a></p>

python linux devops pexpect