title: cygwin ssh via windows cmd removes double quotes
body: <p>I've got two windows machines running the latest version of cygwin.  I have OpenSSH configured on both of them, and password-less authentication has been set up for the remote machine.  I can ssh into either machine without problems.  <strong>All commands below are executed in cmd.exe</strong>.  </p>
  
  <p>System Specification (identical for both machines): </p>
  
  <ul>
  <li>Cygwin version 1.7.32</li>
  <li>Windows 7</li>
  <li>ver from cmd returns "Microsoft Windows [Version 6.1.7601]"</li>
  <li>R 2.14.1</li>
  </ul>
  
  <p>The basic form of my problem is this.  I have to start an executable on my remote machine.  I must start this executable via ssh through windows command line, not cygwin.  That executable has a couple parameters.  One of these parameters needs to be encapsulated within double quotes (Because I am working with a third party package in R, which makes a call to system(), and one parameter expects a string).  The actual parameter is -e "parallel:::.slaveRSOCK()"</p>
  
  <p>The script.exe called below is the file Rscript.exe.  This comes with any (to my knowledge) installation of R.  I did not create it, compile it, or anything.  It is just utilized by the package I am trying to debug, as it allows you to execute R commands outside of the R console gui. The package I am trying to debug is "parallel", which I am using to run parallel processes on remote machines.  I also did not have any hand in creating or compiling this code.</p>
  
  <p>Maybe needless additional info, but the portion of the package I'm trying to debug is the function that spins up a process on a remote machine.  This function develops a command, given some parameters, and executes this command in cmd.exe.  I'm trying to replicate the command and manually execute, as when running through the actual package the process simply hangs.</p>
  
  <p>If I were starting the executable on <strong><em>my</em></strong> machine, I would do the following, in windows cmd.</p>
  
  <pre><code>C:\Path\script.exe -e "parallel:::.slaveRSOCK()" 
  </code></pre>
  
  <p>And this works fine. Establishing an ssh connection to the remote machine and subsequently running this command (changing C to c) also works. </p>
  
  <p>But, when I make the following call for starting this script on the <strong><em>remote</em></strong> machine from my machine</p>
  
  <pre><code>ssh remoteHost c:/Path/script.exe -e "parallel:::.slaveRSOCK()"
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code>bash: -c: line 0: syntax error near unexpected token '('
  bash: -c: line 0: 'c:/Path/script.exe -e parallel:::.slaveRSOCK()'
  </code></pre>
  
  <p>So I've lost the double quotes, obviously I'm not escaping them correctly.  I've tried the following call. which was close </p>
  
  <pre><code>ssh remoteHost c:/Path/script.exe -e \"parallel:::.slaveRSOCK()\"
  </code></pre>
  
  <p>but the second line of the error gave me</p>
  
  <pre><code>bash: -c: line 0: 'c:/Path/script.exe -e \parallel:::.slaveRSOCK()"' 
  </code></pre>
  
  <p>Doesn't make a whole lot of sense to me, as I managed to escape the second quote but the first disappears, and I'm left with a \ before parallel.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This one, as suggested in one of the answers</p>
  
  <pre><code>ssh remoteHost "c:/Path/script.exe -e \"parallel:::.slaveRSOCK()\""
  </code></pre>
  
  <p>gave me the following error</p>
  
  <pre><code>bash: -c: line 0: 'c:/Path/script.exe -e \parallel:::.slaveRSOCK()\'
  </code></pre>
  
  <p>Also quite an odd result, we lose both double quotes but keep the escapes</p>
  
  <p>I've also tried various combinations of double quotes (single quotes) around the whole command after ssh remoteHost, and using the ^ to escape , but now it has pretty much turned into taking shots in the dark, so I thought it may be a good idea to turn to people more knowledgeable than me.</p>
  
  <p>Any help or insight that can be provided is much appreciated.  If there are any questions let me know.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Here are some simple examples of the odd escaping that's going on.</p>
  
  <p>Call:</p>
  
  <pre><code>ssh otherhost echo \"hello()\"
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code> bash: -c: line 0: unexpected EOF while looking for matching '"'
   bash: -c: line 0: syntax error: unexpected end of file
  </code></pre>
  
  <p>Call:</p>
  
  <pre><code>ssh otherhost echo \"hello()"
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>hello()
  </code></pre>
  
  <p>Call:</p>
  
  <pre><code>ssh otherhost echo '\"hello()\" '
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>"hello()"
  </code></pre>
  
  <p>Call:</p>
  
  <pre><code>ssh otherhost echo "\"hello()\""
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>hello\(\)
  </code></pre>
  
  <p>Alternatively, an explanation of this behavior would be appreciated.</p>