在 Linux 中查找软件包的二进制文件

Posted

技术标签:

【中文标题】在 Linux 中查找软件包的二进制文件【英文标题】:Finding a binary for a package in Linux 【发布时间】:2020-04-14 23:27:33 【问题描述】:

我正在整理一个包,但是我似乎没有找到让包在系统中找到二进制文件的方法,请注意下面的代码:

    find_nim <- function(message=TRUE) 
  nimexe <- ""
  if (.Platform$OS.type == "unix") 
      nimexe <- try(system2("which", "nim", stdout=TRUE))
      if (message) message("Nim found at ", nimexe)
   else 
    message("Unrecognized operating system.")
  
#  if (nimexe=="") message("nim executable not found.\n Specify the location of your nim executable.")
  return(nimexe)

这会在安装包时返回:

Warning in system2("which", "nim", stdout = TRUE) :
  running command ''which' nim' had status 1
Nim found at 
Error: package or namespace load failed for ‘nimrmarkdown’:
 .onAttach failed in attachNamespace() for 'nimrmarkdown', details:
  call: if (nimexe != "") 
  error: argument is of length zero

相同的代码在 R 中本地工作。

在包开发中检查系统上的二进制文件的正确方法是什么?

【问题讨论】:

【参考方案1】:

R 本身有 Sys.which() 你可以使用:

R> Sys.which("emacs")
           emacs 
"/usr/bin/emacs" 
R> Sys.which("does_not_exist")
does_not_exist 
            "" 
R> 

Writing R Extensions 手册也提到了这一点:

 Usage of external commands should always be conditional on a test
 for existence (perhaps using 'Sys.which'), as well as declared in
 the 'SystemRequirements' field.

 example in some locales.  (Use e.g. 'capabilities()' or
 'nzchar(Sys.which("someprogram"))' to test for features needed in
 the examples wherever possible, and you can also use 'try()' or

【讨论】:

以上是关于在 Linux 中查找软件包的二进制文件的主要内容,如果未能解决你的问题,请参考以下文章

linux strings-在对象文件或二进制文件中查找可打印的字符串

linux where is命令怎么用

linux下软件的安装与卸载方法

centos系统怎么查看软件安装路径

(办公)记事本_Linux查找命令

linux whereis-查找二进制程序代码等相关文件路径