具有 space、多个驱动器的 Powershell 文件路径

Powershell file path with space, multiple drives

我正在尝试使用调用运算符 (&) 来 运行 R 脚本,但出于某种原因,我无法定向到 D:\ 驱动器上的正确路径,但它可以工作在 C:\ 驱动器上正常(将 R 文件夹从 D:\ 复制到 C:\ 进行测试)。

D:\ 驱动器错误看起来像 space 错误,即使 string/variable 两边有引号。

"Program" 和 "Files" 之间的双倍间距,调用命令正确读取。

理想情况下,我想在 D:\ 驱动器上调用 Rscript.exe,但我不知道为什么它会给我一个错误 - 特别是当 C:\ 驱动器工作正常并且双倍间距读取时正确。

同样值得注意的是 "D:\Program Files (x86)" 也没有正确读取,具有类似的症状。

更新:运行宁

    gci -r d:\ -include rscript.exe | % fullname

returns:

D:\Program Files\R\R-3.2.3\bin\i386\Rscript.exe

D:\Program Files\R\R-3.2.3\bin\x64\Rscript.exe

D:\Program Files\R\R-3.2.3\bin\Rscript.exe

最后一个是我的变量 $RscriptD 设置的内容。

您图片中的第一条错误消息是:

Rscript.exe : The term 'D:\Program' is not recognized as an internal or external command

此消息表示呼叫操作员 (&) 呼叫了 Rscript.exe,但 Rscript.exe 无法使用 'D:\Program' 执行某事。

我不知道 Rscript.exe 的内部过程的确切细节,但是,我认为 Rscript.exe 试图 运行 D:\Program Files\R\R-3.2.3\bin\i386\Rscript.exeD:\Program Files\R\R-3.2.3\bin\x64\Rscript.exe但无法处理 Program Files 的空格。因为 manual 说:

Sub-architectures are also used on Windows, but by selecting executables within the appropriate bin directory, R_HOME/bin/i386 or R_HOME/bin/x64. For backwards compatibility there are executables R_HOME/bin/R.exe and R_HOME/bin/Rscript.exe: these will run an executable from one of the subdirectories, which one being taken first from the R_ARCH environment variable, then from the --arch command-line option and finally from the installation default (which is 32-bit for a combined 32/64 bit R installation).

据此,我认为直接调用 i386/Rscript.exe 或 x64/Rscript.exe 比 bin/Rscript.exe 更好,后者只是为了向后兼容。