title: Executing multiple commands using exec_command
body: <p>After logging in to a remote machine i want to &quot;cd&quot; to a particular directory and execute a command in the &quot;exec_command&quot; using the paramico module . But unable to do that. Am using &quot;;&quot; in between two commands but still unable to get the expected output.</p>
  <pre><code>import paramiko
  
  ssh = paramiko.SSHClient()
  ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  ssh.connect(&quot;10.73.73.242&quot;, username=&quot;root&quot;, password=&quot;dangerous&quot;)
  print 'running remote command'
  stdin, stdout, stderr = ssh.exec_command(&quot;cd /usr/ABC/PGMS;pwd&quot;)
  x = stdout.readlines()
  print &quot;VALUES&quot;,x
  z=stderr.readlines()  
  print &quot;err are&quot;,z
  stdin, stdout, stderr = ssh.exec_command(&quot;ls&quot;)
  x = stdout.readlines()
  print &quot;VALUES ARE AGAIN&quot;,x
  ssh.close()
  </code></pre>
  <p>Here i want to change dir to a directory &quot;/usr/ABC/PGMS&quot; execute &quot;pwd&quot; but its not working. Am clueless about what am doing wrong.</p>
  <h2>The output is as below</h2>
  <blockquote>
  <p>running remote command</p>
  <p>VALUES ['/root\n']</p>
  <p>err are ['bash: line 0: cd: /usr/ABC/PGMS/: No such file or directory\n']</p>
  <p>VALUES ARE AGAIN ['Desktop\n', 'Documents\n', 'autoinst.xml\n', 'bin\n', &gt;'dup_rm_ordr.py\n', 'fullwrite.log\n', 'inst-sys\n', 'pexpect-2.3\n', &gt;'pexpect-2.3.tar.gz\n', 'read_print_matrix.py\n', 'remove_dup.py\n', &gt;'runlog\n']</p>
  </blockquote>
  <p>Still &quot;pwd&quot; shows the /root dir and lists the files and directories in /root.</p>