Let's assume that we have command X
which can be executed in shell and return some result in stdout and stderr. Is it possible to do this from R or/and Matlab? And if yes, how can the result of command be handled?
you can use the system() command to execute shellscripts, system-commands, etc in R
it's documented at http://cran.r-project.org/doc/manuals/R-lang.html#System-and-foreign-language-interfaces
According to this post, you can call anything from any OS, using the system function. An Examples is [status, result] = system(’dir’);
, to call the dir
command on a UNIX-like OS.
From MathWorks documentation:
system('command')
calls upon the operating system to run the specified command, for example dir or ls or a UNIX shell script, and directs the output to the MATLAB software. The command executes in a system shell, which might not be the shell from which you launched MATLAB. If command runs successfully, ans is 0. If command fails or does not exist on your operating system, ans is a nonzero value and an explanatory message appears.
[status, result] = system('command')
calls upon the operating system to run command, and directs the output to MATLAB. If command runs successfully, status is 0 and result contains the output from command. If command fails or does not exist on your operating system, status is a nonzero value and result contains an explanatory message.
See Michael Katz's blog here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With