簡體   English   中英

從R運行.exe:Linux而非Windows上的狀態127警告

[英]running .exe from R: status 127 warning on Linux not on Windows

我正在使用system("script.exe object")從R調用.exe

我得到Warning: running command had status 127 我知道這意味着沒有找到.exe文件。

我在窗戶上。 當我使用shell而不是system它就像一個魅力。 但是,我正在設計一個將在Linux環境(shinyapps.io)中部署的Shiny應用程序。 這就是為什么我需要使用system

編輯

在Windows上,它的工作原理與system(paste("cmd.exe /c", "script.exe object"), intern = FALSE, wait = TRUE)的建議在這里 但是當我在Linux上部署應用程序時卻沒有。

暗示

在Windows本地上,如果我用system2替換systemsystem2(paste("cmd.exe /c", "script.exe object"), wait = TRUE) ,它將引發status 127警告,並且輸出與以下內容完全相同在我在Linux上部署的應用程序中

在此處創建可復制的示例很困難,但是如果需要,我可以嘗試。 請告訴我。

上下文:基本上, .exe是一個黑匣子(編譯的C ++代碼),它使用.txt文件作為輸入並輸出另一個.txt文件。 我正在使用R將.txt文件轉儲到當前工作目錄,然后讀回.exe生成的.txt文件(在當前工作目錄中創建,該文件存儲.exe文件)。

只需添加\\"就可以解決您的問題,例如

> setwd("W:/www/ADemo/")
> system(paste0(getwd(),"/Hi 2.exe"))
Hello, world.
> setwd("W:/www/A Demo/")
> system(paste0(getwd(),"/Hi 2.exe"))
Warning message:
running command 'W:/www/A Demo/Hi 2.exe' had status 127 
> system(paste0("\"",getwd(),"/Hi 2.exe","\" "))
Hello, world.

更新:
當路徑中有空格時,通常會看到127錯誤。 還需要擔心應用程序的輸入,例如"/path A/A 2" --in-path "/home/A/BC/d 123.dta" 以下是一些更新注釋:

  1. system(shQuote(paste0(getwd(),"/Hi 2.exe")))更加方便。
  2. 至少在R 3.2.4中, system()手冊建議改用system2()以避免Win / Linux / OSX /下的路徑問題。

更新2:
對於Linux用戶,我創建了一個函數來檢測您的工作目錄中的給定文件是否可執行:

chkpermission<-function(file, mode='0777'){
 exe_list <- system("echo `ls -l | grep -E ^-.{2}x\\|^-.{5}x\\|^-.{8}x` | awk '{print $9}'", intern=T)
 if(length(exe_list)==0){
    stop("no file is executable");
    ##Make sure you know what you are doing here, add a+x permission:
    ##  if (!(file%in%exe_list)) Sys.chmod(file, mode = mode)
  }
 return(file%in%exe_list);
}

我已經在GNU awk / grep上對其進行了測試。 2/5/8表示[u / 2] ser,[g / 5]組合,[o / 8]等的可執行許可,可以對其進行更改以滿足要求。

問題實際上源於.exe文件僅是Windows可執行文件的事實。 它在Linux環境中不是開箱即用的(您可以使用WINE,但在我的情況下是不可能的,因為我是從R內部調用可執行文件的,我在使用的虛擬機上沒有任何sudo權限或任何權限。我的應用的主機)。 因此,我在Linux虛擬機上編譯了使用g ++編寫的c ++代碼,並使用了.out文件而不是.exe文件。

然后在我的R腳本中,我只需要以下兩個調用:

system("chmod a+x script.out") # to make Linux understand that the file is an executable system("./script.out object") # to run the script

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM