title: How do I use pexpect to run things in the background?
body: <p>I am using the <code>'Pexpect'</code> library in a script and wanted to do some operations after that. What I am doing is as follows:</p>
  
  <pre><code>def child():
          pexpect.spawn("ssh tranzmeo@192.168.21.110")
          child.expect(".*password.*")
          child.sendline('tranzmeo1@#')
          print(child.before)
          child.interact()
          return
  </code></pre>
  
  <p>This is a function I call from another file (which I call training.) When I run training, the <code>child()</code> is called, but immediately it stops the program and enters into the <code>tranzmeo</code> console, which I don't want. I need to <code>ssh</code> into it and do some operations in the background in tranzmeo. How can I do that using pexpect?</p>
  
  <p>My <code>operation</code> is as follows(just for your reference):</p>
  
  <pre><code>def scp(tensorflow_file_location_temp ,tensorflow_file_loc)
          child = pexpect.spawn("scp -r " + tensorflow_file_location_temp + "models@192.168.21.117:" + tensorflow_file_location )
          child.expect(".*password.*")
          child.sendline('Tranzmeo1@#')
          child.interact()
  </code></pre>