【问题标题】:issue when calling executable in a path that has space在有空间的路径中调用可执行文件时出现问题
【发布时间】:2018-03-25 10:06:44
【问题描述】:

我刚刚在一台新的 Microsoft Windows 7 计算机上安装了 R,使用命令行时出现以下错误:

"C:\Program Files\R\R-3.3.2\bin\Rscript.exe" --version  
'C:\Program' is not recognized as an internal or external command,

可运行的程序或批处理文件。

请注意,我在路径周围的引号上方添加了一个空格。并且我在系统路径中添加了:

;C:\Program Files\R\R-3.3.2\bin\

有趣的是:

  1. 如果我只是调用它Rscript.exe --version 它会给出同样的错误,这很奇怪:如果它找到它,为什么它不能运行它!?! 我能找到的唯一解释是查找Rscript.exe的依赖时出现错误
  2. 我还注意到 "C:\Program Files\R\R-3.3.3\bin\x64\Rscript.exe" --version 可以正常工作(...\bin...\bin\x64 两个文件夹都有一个可执行的 Rscript.exe)

最后我确认这是一个特定于 R 的问题,因为我在 Program Files 的子文件夹中尝试的所有其他可执行文件都可以通过相同的命令行界面调用!

【问题讨论】:

  • 您的 Q 标题似乎与您的 Q 无关?
  • @MichaelChirico 这不是一个真正的 R 问题 :-)
  • 无法重现。调用>"C:\Program Files\R\R-3.3.3\bin\Rscript.exe" --version 导致R scripting front-end version 3.3.3 (2017-03-06)
  • @Heikki 你真幸运!
  • 你们投票结束但我的问题是有效的......并记录在案。如果标题中有任何需要改进的地方,您可以提出建议或修改

标签: r path environment-variables command-line-interface


【解决方案1】:

我一直在尝试复制您的问题,但在您的问题中发现了一件事:您提到这不起作用:

"C:\Program Files\R\R-3.3.2\bin\Rscript.exe" --version  
'C:\Program' is not recognized as an internal or external command,

但这确实:

"C:\Program Files\R\R-3.3.3\bin\x64\Rscript.exe" --version

您似乎在有效的示例中使用了 R-3.3.3,而在无效的示例中使用了 R-3.3.2。

所以我假设如果你把它改成

"C:\Program Files\R\R-3.3.3\bin\Rscript.exe" --version  

它应该可以工作。

【讨论】:

    【解决方案2】:

    看看

    C:\Users>Rscript --help
    Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]
    
    --options accepted are
      --help              Print usage and exit
      --version           Print version and exit
      --verbose           Print information on progress
      --default-packages=list
                          Where 'list' is a comma-separated set
                            of package names, or 'NULL'
    or options to R, in addition to --slave --no-restore, such as
      --save              Do save workspace at the end of the session
      --no-environ        Don't read the site and user environment files
      --no-site-file      Don't read the site-wide Rprofile
      --no-init-file      Don't read the user R profile
      --restore           Do restore previously saved objects at startup
      --vanilla           Combine --no-save, --no-restore, --no-site-file
                            --no-init-file and --no-environ
    
    'file' may contain spaces but not shell metacharacters
    Expressions (one or more '-e <expr>') may be used *instead* of 'file'
    See also  ?Rscript  from within R
    

    根据您的理论,某些依赖存在错误,我希望 --verbose 能指示 Rscript 尝试读取的其他文件。没有这样的运气。

    顺便说一句,除非我也为 Rscript 提供一些命令,否则这些选项几乎都对我不可用——否则它会一直抱怨“文件名丢失”。因此,对于这些可能性中的任何一种,您都可以选择

    C:\Users>Rscript --verbose -e print(2+2)
    

    话虽如此,您可以通过使用--no-environ--no-site-file--vanilla 等选项来进一步追求您的理论,使其跳过任何文件依赖项,看看它是否能让您有所收获。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多