Running remote ssh command with spaces?
Solution 1
I found this worked for me, although it was not related to paths, but services:
ssh username@ipaddress 'net start \"TightVNC Server\"'
Solution 2
The OpenSSH ssh
is *nix application, so *nix rules apply when parsing its command-line
ssh user@ipaddress "python \"C:\folder path\file.py\""
Related videos on Youtube
lukehawk
Updated on September 18, 2022Comments
-
lukehawk over 1 year
I am trying to run a remote script in windows over ssh, and I cannot figure out how to handle the quotes. (Both host and client are windows machines.) This is the statement which works fine on the host machine:
C:\> python "C:\folder path\file.py"
I have looked seemingly everywhere, and tried seemingly everything, but I cannot get this to work:
C:\> ssh user@ipaddress "python ""C:\folder path\file.py""" python: can't open file 'C:\folder': [Errno 2] No such file or directory
I have tried using double quotes, I have tried single quotes, I have tried '\' as an escape character, I have tried '^', and nothing seems to pass the string correctly. Any help?!
EDIT: A user suggested I use '-v' with ssh to track the path. Doing that, it looks like the double quotes actually do what I expect, but somehow the host machine misinterprets the command, and objects to the space. Not sure why...
To be clear, using this:
C:\> ssh -v user@ipaddress "python ""C:\folder path\file.py"""
I see this in the results:
debug1: Sending command: python "C:\folder path\file.py" python: can't open file 'C:\folder': [Errno 2] No such file or directory
AGAIN, to be more clear, this command works PERFECTLY when I am phsyically at the host machine:
C:\> python "C:\folder path\file.py"
So, I am unclear why/where this is getting screwed up. Thanks for any help, you all have helped immensely thus far.
-
lukehawk over 7 yearsThanks for this, but it does not work. I still get the same error. I used the '-v' option with ssh to try and track the problem. Using double quotes looks like it passes the correct string, but for some reason it gets misinterpreted by the host machine. See above.
-
Martin Prikryl over 7 yearsThen you will have to tell more about your setup. What is the server? What SSH server is that? What is the
ssh
? I assume OpenSSHssh
, but what build? MS? CygWin? -
lukehawk over 7 yearsEverything is windows, both the host and the client. I followed the instructions here - winscp.net/eng/docs/guide_windows_openssh_server, which linked to github.com/PowerShell/Win32-OpenSSH/releases, which is what i installed.
-
Martin Prikryl over 7 yearsI'm having an exactly same setup (I have actually written the guide you had used). And it works for me with the
\"
. -
ThorSummoner about 3 yearsin case this helps save anyone else's sanity:
ssh myuser@mywin10host -t '\"C:\Program Files\Git\bin\bash.exe\" -l'