pexpect child.before and child.after is empty
<pre><code>&gt;&gt;&gt; ssh_stuff
['yes/no', 'Password:', 'password', 'Are you sure you want to continue connecting']
&gt;&gt;&gt; prompt
['$', '#']
&gt;&gt;&gt; child = pexpect.spawn('ssh kumarshubham@localhost')
&gt;&gt;&gt; child.expect(ssh_stuff)
1
&gt;&gt;&gt; child.sendline(getpass.getpass())
Password: 
11
&gt;&gt;&gt; child.expect(prompt)
0
&gt;&gt;&gt; child.sendline('ls -l')
6
&gt;&gt;&gt; child.expect(prompt)
0
&gt;&gt;&gt; print child.before, child.after
</code></pre>

<p>can one tell me why my child.before and after is empty, it should return directory listing.</p>

<p>To match a literal <code>$</code> char you have to use <code>\$</code> so try with <code>prompt = ['\$', '#']</code> (or simply <code>prompt = '[$#]'</code>). And according to pexpect's doc:</p>

<blockquote>
  <p>The <code>$</code> pattern for end of line match is useless. The <code>$</code> matches the end of string, but <code>Pexpect</code> reads from the child one
  character at a time, so <strong>each character looks like the end of a line</strong>.</p>
</blockquote>

python pexpect