使用 Plink 执行包含单引号的命令时出现问题

Issue in executing command containing single quote using Plink

我在 Windows 10 中使用 cmd 中的 plink.exe,通过 ssh 连接到 Ubuntu 16.04。在那里,我 运行ning MATLAB,运行 以下命令:

try, someFunction('path/to/files', 'algorithm'), exit(); catch ME, warning(ME.message), exit(); end

为此,我生成以下命令来处理 ssh,执行 matlab 和 运行 上述命令:

C:\plink.exe user@server -pw ****** "matlab -nodesktop -nosplash -noawt -r 'try, someFunction('path/to/files', 'algorithm'), exit(); catch ME, warning(ME.message), exit(); end'

运行 上述命令,我在 MATLAB 中得到以下错误:

Warning: Undefined function or variable 'path/to/files'.

事实证明,在 matlab 中,命令的构造如下:

someFunction(path/to/files, algorithm)

没有"single quotes":谢谢,plink :( .

你能帮忙生成正确的命令吗?或者如果已经有类似问题的问题,我将不胜感激。

谢谢,

不是Plink的问题。这就是 Windows 命令行解释器的工作方式。

添加 and 标签,以便您可以从该领域的专家那里得到答案。


无论如何,我可以看到两个解决方案:

  • 将您的命令放入一个文件,例如:

    matlab -nodesktop -nosplash -noawt -r "try, someFunction('path/to/files', 'algorithm'), exit(); catch ME, warning(ME.message), exit(); end"
    

    并将文件 (command.txt) 与 Plink 一起使用,例如:

    C:\plink.exe user@server -pw ****** -m command.txt
    
  • 如果您不想为命令使用单独的文件,这也应该有效:

    echo matlab -nodesktop -nosplash -noawt -r "try, someFunction('path/to/files', 'algorithm'), exit(); catch ME, warning(ME.message), exit(); end" | C:\plink.exe user@server -pw ****** -T
    

    (注意 -T 开关)。