title: Run batch file remotely using ssh and copy the result to a text?
body: <p>I need to run a batch script remotely using <code>ssh</code> and <code>expect</code> and copy the result to a text file. How do I do that?</p>
  
  <p>This works:   </p>
  
  <pre><code> $ ssh -t username@dshost 'D:\scripts\a.bat' &gt;file.txt
  </code></pre>
  
  <p>But this doesn't:</p>
  
  <pre><code>#! /usr/bin/expect --
  spawn ssh -t username@shost  'D:\\scripts\\a.bat' &gt;file.txt
  expect "*assword:*" { send "pwd\r" }    
  expect "yes/no"     send "yes\r"
  exit
  </code></pre>
  
  <p>I am getting the following error.</p>
  
  <pre><code>The filename, directory name, or volume label syntax is incorrect.
  </code></pre>