How to execute a R script file from java












0















I would like to call an R script from Java. I have done google searches on the topic, but almost all of the results I have seen would require me to add a dependency to some third party library. Can anyone show me a good way to accomplish the same thing without adding any dependencies to my code?



I'm setting up a new application which runs R script file from java using the following line




Runtime.getRuntime().exec("C:UsersThiruDesktop helloWorld.R");




but when I run the application I am getting following exception:



SEVERE: Servlet.service() for servlet [RenjinServlet] in context with 
path
[/REngineCheck] threw exception
java.io.IOException: Cannot run program "C:UsersThiruDesktop":
CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at org.r.Check.RenjinServlet.doGet(RenjinServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:291)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke
(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke
(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun
(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run
(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run
(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 28 more









share|improve this question

























  • If your windows is not configured to use Rscript to run files ending in .R, you may need to do Runtime.getRuntime().exec("C:pathtoRscript.exe C:UsersThiruDesktophellowWorld.R"). (I'm not familiar enough with java to know for sure if that should be a string with the cmd and all args, or if you need to pass a list with the cmd as the first, and your R script as the second element.)

    – r2evans
    Dec 29 '18 at 18:58











  • Dear @r2evans, It's not working I am getting file not found exception, but when I run like this in CMD I am getting the out put in cmd. E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R

    – Bharath Pateru
    Dec 31 '18 at 10:55











  • What happens if you try Runtime.getRuntime().exec("E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R")?

    – r2evans
    Dec 31 '18 at 16:13











  • @r2evans, I am getting file not found exception when I run like this.

    – Bharath Pateru
    Jan 4 at 5:27











  • My guess (again, not a java guy) is that it had to do with including both the executable and its argument(s) in one string. Do you know how to use Runtime.getRuntime().exec? I do not.

    – r2evans
    Jan 5 at 13:39
















0















I would like to call an R script from Java. I have done google searches on the topic, but almost all of the results I have seen would require me to add a dependency to some third party library. Can anyone show me a good way to accomplish the same thing without adding any dependencies to my code?



I'm setting up a new application which runs R script file from java using the following line




Runtime.getRuntime().exec("C:UsersThiruDesktop helloWorld.R");




but when I run the application I am getting following exception:



SEVERE: Servlet.service() for servlet [RenjinServlet] in context with 
path
[/REngineCheck] threw exception
java.io.IOException: Cannot run program "C:UsersThiruDesktop":
CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at org.r.Check.RenjinServlet.doGet(RenjinServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:291)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke
(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke
(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun
(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run
(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run
(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 28 more









share|improve this question

























  • If your windows is not configured to use Rscript to run files ending in .R, you may need to do Runtime.getRuntime().exec("C:pathtoRscript.exe C:UsersThiruDesktophellowWorld.R"). (I'm not familiar enough with java to know for sure if that should be a string with the cmd and all args, or if you need to pass a list with the cmd as the first, and your R script as the second element.)

    – r2evans
    Dec 29 '18 at 18:58











  • Dear @r2evans, It's not working I am getting file not found exception, but when I run like this in CMD I am getting the out put in cmd. E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R

    – Bharath Pateru
    Dec 31 '18 at 10:55











  • What happens if you try Runtime.getRuntime().exec("E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R")?

    – r2evans
    Dec 31 '18 at 16:13











  • @r2evans, I am getting file not found exception when I run like this.

    – Bharath Pateru
    Jan 4 at 5:27











  • My guess (again, not a java guy) is that it had to do with including both the executable and its argument(s) in one string. Do you know how to use Runtime.getRuntime().exec? I do not.

    – r2evans
    Jan 5 at 13:39














0












0








0








I would like to call an R script from Java. I have done google searches on the topic, but almost all of the results I have seen would require me to add a dependency to some third party library. Can anyone show me a good way to accomplish the same thing without adding any dependencies to my code?



I'm setting up a new application which runs R script file from java using the following line




Runtime.getRuntime().exec("C:UsersThiruDesktop helloWorld.R");




but when I run the application I am getting following exception:



SEVERE: Servlet.service() for servlet [RenjinServlet] in context with 
path
[/REngineCheck] threw exception
java.io.IOException: Cannot run program "C:UsersThiruDesktop":
CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at org.r.Check.RenjinServlet.doGet(RenjinServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:291)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke
(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke
(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun
(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run
(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run
(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 28 more









share|improve this question
















I would like to call an R script from Java. I have done google searches on the topic, but almost all of the results I have seen would require me to add a dependency to some third party library. Can anyone show me a good way to accomplish the same thing without adding any dependencies to my code?



I'm setting up a new application which runs R script file from java using the following line




Runtime.getRuntime().exec("C:UsersThiruDesktop helloWorld.R");




but when I run the application I am getting following exception:



SEVERE: Servlet.service() for servlet [RenjinServlet] in context with 
path
[/REngineCheck] threw exception
java.io.IOException: Cannot run program "C:UsersThiruDesktop":
CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at org.r.Check.RenjinServlet.doGet(RenjinServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:291)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke
(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke
(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun
(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run
(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run
(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 28 more






java r rserve jri






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 29 '18 at 11:04









Joey Mallone

1,10121123




1,10121123










asked Dec 29 '18 at 10:51









Bharath PateruBharath Pateru

42112




42112













  • If your windows is not configured to use Rscript to run files ending in .R, you may need to do Runtime.getRuntime().exec("C:pathtoRscript.exe C:UsersThiruDesktophellowWorld.R"). (I'm not familiar enough with java to know for sure if that should be a string with the cmd and all args, or if you need to pass a list with the cmd as the first, and your R script as the second element.)

    – r2evans
    Dec 29 '18 at 18:58











  • Dear @r2evans, It's not working I am getting file not found exception, but when I run like this in CMD I am getting the out put in cmd. E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R

    – Bharath Pateru
    Dec 31 '18 at 10:55











  • What happens if you try Runtime.getRuntime().exec("E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R")?

    – r2evans
    Dec 31 '18 at 16:13











  • @r2evans, I am getting file not found exception when I run like this.

    – Bharath Pateru
    Jan 4 at 5:27











  • My guess (again, not a java guy) is that it had to do with including both the executable and its argument(s) in one string. Do you know how to use Runtime.getRuntime().exec? I do not.

    – r2evans
    Jan 5 at 13:39



















  • If your windows is not configured to use Rscript to run files ending in .R, you may need to do Runtime.getRuntime().exec("C:pathtoRscript.exe C:UsersThiruDesktophellowWorld.R"). (I'm not familiar enough with java to know for sure if that should be a string with the cmd and all args, or if you need to pass a list with the cmd as the first, and your R script as the second element.)

    – r2evans
    Dec 29 '18 at 18:58











  • Dear @r2evans, It's not working I am getting file not found exception, but when I run like this in CMD I am getting the out put in cmd. E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R

    – Bharath Pateru
    Dec 31 '18 at 10:55











  • What happens if you try Runtime.getRuntime().exec("E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R")?

    – r2evans
    Dec 31 '18 at 16:13











  • @r2evans, I am getting file not found exception when I run like this.

    – Bharath Pateru
    Jan 4 at 5:27











  • My guess (again, not a java guy) is that it had to do with including both the executable and its argument(s) in one string. Do you know how to use Runtime.getRuntime().exec? I do not.

    – r2evans
    Jan 5 at 13:39

















If your windows is not configured to use Rscript to run files ending in .R, you may need to do Runtime.getRuntime().exec("C:pathtoRscript.exe C:UsersThiruDesktophellowWorld.R"). (I'm not familiar enough with java to know for sure if that should be a string with the cmd and all args, or if you need to pass a list with the cmd as the first, and your R script as the second element.)

– r2evans
Dec 29 '18 at 18:58





If your windows is not configured to use Rscript to run files ending in .R, you may need to do Runtime.getRuntime().exec("C:pathtoRscript.exe C:UsersThiruDesktophellowWorld.R"). (I'm not familiar enough with java to know for sure if that should be a string with the cmd and all args, or if you need to pass a list with the cmd as the first, and your R script as the second element.)

– r2evans
Dec 29 '18 at 18:58













Dear @r2evans, It's not working I am getting file not found exception, but when I run like this in CMD I am getting the out put in cmd. E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R

– Bharath Pateru
Dec 31 '18 at 10:55





Dear @r2evans, It's not working I am getting file not found exception, but when I run like this in CMD I am getting the out put in cmd. E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R

– Bharath Pateru
Dec 31 '18 at 10:55













What happens if you try Runtime.getRuntime().exec("E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R")?

– r2evans
Dec 31 '18 at 16:13





What happens if you try Runtime.getRuntime().exec("E:E DriveSoftwaresR docsR-3.5.1binx64>Rscript C:UsersThiruDesktophelloWorld.R")?

– r2evans
Dec 31 '18 at 16:13













@r2evans, I am getting file not found exception when I run like this.

– Bharath Pateru
Jan 4 at 5:27





@r2evans, I am getting file not found exception when I run like this.

– Bharath Pateru
Jan 4 at 5:27













My guess (again, not a java guy) is that it had to do with including both the executable and its argument(s) in one string. Do you know how to use Runtime.getRuntime().exec? I do not.

– r2evans
Jan 5 at 13:39





My guess (again, not a java guy) is that it had to do with including both the executable and its argument(s) in one string. Do you know how to use Runtime.getRuntime().exec? I do not.

– r2evans
Jan 5 at 13:39












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968857%2fhow-to-execute-a-r-script-file-from-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968857%2fhow-to-execute-a-r-script-file-from-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas