【发布时间】:2016-09-09 02:54:26
【问题描述】:
我有一个 Matlab 函数,它可以找到这个函数在我的电脑中的路径,然后在同一目录上运行一个 bat 文件。此 bat 文件旨在执行 R 脚本,但由于奇怪的原因未能执行。
这是我的 Matlab 函数:
function [] = myFunction(arg)
% Find the directory of the executing script
thisDir = fileparts(mfilename('fullpath'));
% Save arg as a csv on this directory, this will be read by my R script
tmpDir = strcat(thisDir,'/tmp.csv');
csvwrite(tmpDir,arg);
% Specify the command to run
dosCommand = ['call "' thisDir '/runRscript.bat"'];
dos(dosCommand);
end
bat文件代码如下:
"C:\Program Files\R\R-3.2.2\bin\x64\R.exe" CMD BATCH runRScipt.R
当我在 Matlab 中运行该函数时,我收到以下消息:
C:\Users\...mypath...>"C:\Program Files\R\R-3.2.2\bin\x64\R.exe" CMD BATCH 运行Rscript.R
自从我在 Matlab 中收到此消息以来,我毫不怀疑它正在查找和读取批处理文件,但它无法执行 R 脚本。我知道 bat 文件按预期工作,因为我可以通过命令行(使用 Matlab 脚本上的“dosCommand”命令)或在 .bat 文件上单击两次来运行它。
【问题讨论】:
标签: r windows matlab batch-file cmd