简体   繁体   中英

cygwin ssh via windows cmd removes double quotes

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. All commands below are executed in cmd.exe .

System Specification (identical for both machines):

  • Cygwin version 1.7.32
  • Windows 7
  • ver from cmd returns "Microsoft Windows [Version 6.1.7601]"
  • R 2.14.1

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()"

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.

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.

If I were starting the executable on my machine, I would do the following, in windows cmd.

C:\Path\script.exe -e "parallel:::.slaveRSOCK()" 

And this works fine. Establishing an ssh connection to the remote machine and subsequently running this command (changing C to c) also works.

But, when I make the following call for starting this script on the remote machine from my machine

ssh remoteHost c:/Path/script.exe -e "parallel:::.slaveRSOCK()"

I get the following error

bash: -c: line 0: syntax error near unexpected token '('
bash: -c: line 0: 'c:/Path/script.exe -e parallel:::.slaveRSOCK()'

So I've lost the double quotes, obviously I'm not escaping them correctly. I've tried the following call. which was close

ssh remoteHost c:/Path/script.exe -e \"parallel:::.slaveRSOCK()\"

but the second line of the error gave me

bash: -c: line 0: 'c:/Path/script.exe -e \parallel:::.slaveRSOCK()"' 

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.

EDIT

This one, as suggested in one of the answers

ssh remoteHost "c:/Path/script.exe -e \"parallel:::.slaveRSOCK()\""

gave me the following error

bash: -c: line 0: 'c:/Path/script.exe -e \parallel:::.slaveRSOCK()\'

Also quite an odd result, we lose both double quotes but keep the escapes

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.

Any help or insight that can be provided is much appreciated. If there are any questions let me know.

EDIT 2

Here are some simple examples of the odd escaping that's going on.

Call:

ssh otherhost echo \"hello()\"

Returns:

 bash: -c: line 0: unexpected EOF while looking for matching '"'
 bash: -c: line 0: syntax error: unexpected end of file

Call:

ssh otherhost echo \"hello()"

Returns:

hello()

Call:

ssh otherhost echo '\"hello()\" '

Returns:

"hello()"

Call:

ssh otherhost echo "\"hello()\""

Returns:

hello\(\)

Alternatively, an explanation of this behavior would be appreciated.

I think you want:

ssh remoteHost "c:/Path/script.exe -e \"parallel:::.slaveRSOCK()\""

I honestly can't fully explain the reasoning behind the quoting (or what's screwing it up if it's a bug), but I think this will work for you:

ssh remoteHost "c:/Path/script.exe -e \"parallel:::.slaveRSOCK\(\)\""

The complication seems to be the following sequence of things parsing the command line(s):

  1. Windows cmd.exe on the local machine gets and parses the whole thing
  2. ssh sends the "c:/Path/script.exe -e \\"parallel:::.slaveRSOCK()\\"" portion to sshd on the remote Windows host. I'm not sure in what form sshd gets this command line, or exactly what transformations it might do to it.
  3. sshd apparently invokes bash to run the command (thorough some cygwin mechanism?). Again, I'm not sure of the exact form the command line that gets to bash.
  4. bash gets confused unless the parens are escaped, and the backslashes seem to get far enough through this assembly line of processes to make bash on the remote windows-with-cygwin machine happy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM