从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
文件.
I get Warning: running command had status 127
. I know it means the .exe
file has not been found.
我在Windows上.当我使用shell
而不是system
时,它就像一种魅力.但是,我正在设计一个Shiny应用程序,该应用程序将部署在Linux环境中(shinyapps.io).这就是为什么我需要使用system
.
I'm on windows. When I use shell
instead of system
it works like a charm. However, I am designing a Shiny application that will be deployed in a Linux environment (shinyapps.io). This is why I need to use system
.
编辑
在Windows上,建议在此处使用system(paste("cmd.exe /c", "script.exe object"), intern = FALSE, wait = TRUE)
.但是当我在Linux上部署应用程序时没有.
On Windows, it works with system(paste("cmd.exe /c", "script.exe object"), intern = FALSE, wait = TRUE)
as suggested here. But not when I deploy the app (on Linux).
提示
在Windows本地,如果我将system
替换为system2
:system2(paste("cmd.exe /c", "script.exe object"), wait = TRUE)
,则会引发status 127
警告,并且输出与在Linux上部署的应用程序完全相同 .
Locally on Windows, if I replace system
with system2
: system2(paste("cmd.exe /c", "script.exe object"), wait = TRUE)
, it raises the status 127
warning and the output is exactly the same as in my deployed app on Linux.
在此处创建可复制的示例很困难,但如有需要,我可以尝试.请告诉我.
It's tough to create a reproducible example here but if needed I can try. Please tell me.
上下文:基本上.exe
是一个黑盒(编译的C ++代码),它使用.txt文件作为输入并输出另一个.txt文件.我正在使用R将.txt文件转储到当前工作目录,然后回读由.exe
生成的.txt文件(在当前工作目录中创建,该文件存储了.exe
文件).>
Context: basically the .exe
is a black box (compiled C++ code) that takes a .txt file as input and outputs another .txt file. I am using R to dump the .txt file to the current working directory, then read back in the .txt file generated by the .exe
(created in the current working directory, where the .exe
file is stored).
推荐答案
问题实际上源于.exe
文件仅是Windows可执行文件的事实.它在Linux环境中不是开箱即用的(可以使用WINE,但是在我的情况下是不可能的,因为我是从R内部调用可执行文件的,我在虚拟机上没有任何sudo
权限或任何权限由我的应用的主机使用).因此,我在Linux虚拟机上编译了使用g ++编写的c ++代码,并使用了.out
文件而不是.exe
.
The problem actually stemmed from the fact that .exe
files are executables for Windows only. It does not work out of the box on Linux environments (you can use WINE but in my case it is not possible because I am calling the executable from within R, I don't have any sudo
rights or anything on the virtual machine used by the host of my app). So I compiled the c++ code I had using g++ on a Linux virtual machine and used the .out
file rather than the .exe
.
然后在我的R脚本中,我只需要以下两个调用:
Then in my R script I just needed these two calls:
system("chmod a+x script.out") # to make Linux understand that the file is an executable
system("./script.out object") # to run the script
这篇关于从R运行.exe:Linux而非Windows上的状态127警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!