| Q | A
| ----------------- | ---
| Issue Type | Bug
| Deployer Version | 6.2.0
| Local Machine OS | Windows
| Remote Machine OS | Ubuntu 16.04
When using the Win32 port of OpenSSH the ssh command needs to be enclosed by double quotes, because windows executables need double quotes for arguments.
E.g. (when using the Win32 port of OpenSSH)
> ssh.exe [email protected] 'echo "foobar"'
bash: echo foobar: command not found
> ssh.exe [email protected] "echo 'foobar'"
foobar
The Client class produces a command with single quotes, see https://github.com/deployphp/deployer/blob/master/src/Ssh/Client.php#L86
When one changes this to
$ssh = "ssh $sshArguments $host $become \"$shellCommand; printf '[exit_code:%s]' $?;\"";
it will work with the windows ssh.exe, but then shell expansion would be applied to the $shellCommand ($var would be evaluated), which could cause problem (although that change works fine for me).
One way around this, would be to check which ssh.exe is used and then apply the correct quoting style (when using windows $var will not be evaluated, so it should be safe).
$sshVersionProcess = new Process('ssh -V');
$sshVersionProcess->run();
// the version info is on STDERR
if(strpos($sshVersionProcess->getErrorOutput(), 'OpenSSH_for_Windows') !== false){
$ssh = "ssh $sshArguments $host $become \"$shellCommand; printf '[exit_code:%s]' $?;\"";
} else {
$ssh = "ssh $sshArguments $host $become '$shellCommand; printf \"[exit_code:%s]\" $?;'";
}
It would be nice to get the version info only once, but i'm not sure where...
Should i create a pull request for my supposed solution?
Execute deployer deploy with the Win32 port of OpenSSH.
This will probably fix https://github.com/deployphp/deployer/issues/1436.
Maybe one could only rely on just checking if php is run from windows or not (with the PHP_OS-constant) since when it is run from windows, it will need double quotes regardless where ssh.exe comes from (e.g. the older one mentioned in 1436).
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
$ssh = "ssh $sshArguments $host $become \"$shellCommand; printf '[exit_code:%s]' $?;\"";
} else {
$ssh = "ssh $sshArguments $host $become '$shellCommand; printf \"[exit_code:%s]\" $?;'";
}
I ended up merging all the fixes.
https://github.com/digizijn/deployer/
I ended up using capistrano again 馃槈
For the moment that seems to work flawless with windows.
Looking forward to 7.0 to try again.
Works for me on Windows 10.
@marcharding it works for me too. Try to submit a PR to fix this.
This issue (#1640 ) also mention the solution.
Is it working now? Ok to close?
Most helpful comment
I ended up using capistrano again 馃槈
For the moment that seems to work flawless with windows.
Looking forward to 7.0 to try again.