R 3.6.3 OSX and Windows Colleagues I want to identify if Java is installed on a particular computer. When I execute Java -version in a terminal (OSX), but not in R, there are two outcomes: Java installed yields: java version "13.0.1" 2019-10-15 Java(TM) SE Runtime Environment (build 13.0.1+9) Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing) Java not installed yields: No Java runtime installed I assume that there are comparable outputs in Windows. I would like to capture this output in R using the system command, then search for ?No Java runtime installed? )or the correponding text in Windows). I execute something like: CAPTURE <- system("Java -version", intern=TRUE, ignore.stderr=FALSE, ignore.stdout=FALSE) (with various permutations of TRUE/FALSE for the options) but I cannot capture what is displayed on the console. I have also tried ?system2? with various TRUE/FALSE permutations without success. Any clever ideas? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com
I am mystified by your description. A) If java is not installed, the operating system or system shell will be the source of any error associated with attempting to invoke it. That means the error message could be anything, but I find it quite surprising that the message emitted by the OS would mention "runtime". In any event, look for the output you can rely on from java for positive identification rather than looking for any consistent pattern in the error messages for negative confirmation. B) Many OS command shells are case-sensitive... asking for the "Java" program is in that case different than asking for the "java" program. On November 9, 2019 8:51:43 AM PST, Dennis Fisher <fisher at plessthan.com> wrote:>R 3.6.3 >OSX and Windows > >Colleagues > >I want to identify if Java is installed on a particular computer. > >When I execute > Java -version >in a terminal (OSX), but not in R, there are two outcomes: > >Java installed yields: > java version "13.0.1" 2019-10-15 > Java(TM) SE Runtime Environment (build 13.0.1+9) > Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, >sharing) > >Java not installed yields: > No Java runtime installed > >I assume that there are comparable outputs in Windows. > >I would like to capture this output in R using the system command, then >search for ?No Java runtime installed? )or the correponding text in >Windows). > >I execute something like: > CAPTURE <- system("Java -version", intern=TRUE, ignore.stderr=FALSE, >ignore.stdout=FALSE) >(with various permutations of TRUE/FALSE for the options) but I cannot >capture what is displayed on the console. > >I have also tried ?system2? with various TRUE/FALSE permutations >without success. > >Any clever ideas? > >Dennis > >Dennis Fisher MD >P < (The "P Less Than" Company) >Phone / Fax: 1-866-PLessThan (1-866-753-7784) >www.PLessThan.com > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- Sent from my phone. Please excuse my brevity.
Jeff A. I can certainly look for the output from Java ? but that was not the point ? nothing was captured to CAPTURE with either scenarios. B. I tried changing case ? that did not solve the problem. The issue remains ? when I execute the system command, the text output that I presented below is not being displayed. Is there a way to capture that output? If so, I can certainly figure out how to parse it. Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com <http://www.plessthan.com/>> On Nov 9, 2019, at 9:28 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote: > > I am mystified by your description. > > A) If java is not installed, the operating system or system shell will be the source of any error associated with attempting to invoke it. That means the error message could be anything, but I find it quite surprising that the message emitted by the OS would mention "runtime". In any event, look for the output you can rely on from java for positive identification rather than looking for any consistent pattern in the error messages for negative confirmation. > > B) Many OS command shells are case-sensitive... asking for the "Java" program is in that case different than asking for the "java" program. > > On November 9, 2019 8:51:43 AM PST, Dennis Fisher <fisher at plessthan.com> wrote: >> R 3.6.3 >> OSX and Windows >> >> Colleagues >> >> I want to identify if Java is installed on a particular computer. >> >> When I execute >> Java -version >> in a terminal (OSX), but not in R, there are two outcomes: >> >> Java installed yields: >> java version "13.0.1" 2019-10-15 >> Java(TM) SE Runtime Environment (build 13.0.1+9) >> Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, >> sharing) >> >> Java not installed yields: >> No Java runtime installed >> >> I assume that there are comparable outputs in Windows. >> >> I would like to capture this output in R using the system command, then >> search for ?No Java runtime installed? )or the correponding text in >> Windows). >> >> I execute something like: >> CAPTURE <- system("Java -version", intern=TRUE, ignore.stderr=FALSE, >> ignore.stdout=FALSE) >> (with various permutations of TRUE/FALSE for the options) but I cannot >> capture what is displayed on the console. >> >> I have also tried ?system2? with various TRUE/FALSE permutations >> without success. >> >> Any clever ideas? >> >> Dennis >> >> Dennis Fisher MD >> P < (The "P Less Than" Company) >> Phone / Fax: 1-866-PLessThan (1-866-753-7784) >> www.PLessThan.com >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- > Sent from my phone. Please excuse my brevity.[[alternative HTML version deleted]]
Dennis, R does that for you already as it needs to know it for rJava too. On my (Linux) box: edd at rob:~$ R CMD config JAVA /usr/lib/jvm/default-java/bin/java edd at rob:~$ R CMD config JAVA_HOME /usr/lib/jvm/default-java edd at rob:~$ You could also do the equivalent of `which` or `type -p` from R: R> Sys.which("javac") javac "/usr/bin/javac" R> Sys.which("javacdoesnotexist") javacdoesnotexist "" R> Hope this helps, Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Hello, Here are two ways. 1. system2 returns the return value of the shell command so if Java is installed, it should return 0. In the first call it's 'java' (lowercase j), in the second 'Java' (uppercase J). java <- system2('java', '-version') java #[1] 0 Java <- system2('Java', '-version') Java #[1] 127 2. Another way is to redirect the shell output to file. In this case I'm redirecting to a temp file. Then, readLines from that file. tmpfile <- tempfile() if(!dir.exists(dirname(tmpfile))) dir.create(dirname(tmpfile)) system2('java', '-version', '>', tmpfile) readLines(tmpfile) unlink(tmpfile) # final cleanup Hope this helps, Rui Barradas ?s 16:51 de 09/11/19, Dennis Fisher escreveu:> R 3.6.3 > OSX and Windows > > Colleagues > > I want to identify if Java is installed on a particular computer. > > When I execute > Java -version > in a terminal (OSX), but not in R, there are two outcomes: > > Java installed yields: > java version "13.0.1" 2019-10-15 > Java(TM) SE Runtime Environment (build 13.0.1+9) > Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing) > > Java not installed yields: > No Java runtime installed > > I assume that there are comparable outputs in Windows. > > I would like to capture this output in R using the system command, then search for ?No Java runtime installed? )or the correponding text in Windows). > > I execute something like: > CAPTURE <- system("Java -version", intern=TRUE, ignore.stderr=FALSE, ignore.stdout=FALSE) > (with various permutations of TRUE/FALSE for the options) but I cannot capture what is displayed on the console. > > I have also tried ?system2? with various TRUE/FALSE permutations without success. > > Any clever ideas? > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
> On Nov 9, 2019, at 8:51 AM, Dennis Fisher <fisher at plessthan.com> wrote: > > R 3.6.3 > OSX and Windows > > Colleagues > > I want to identify if Java is installed on a particular computer. >[...]> I execute something like: > CAPTURE <- system("Java -version", intern=TRUE, ignore.stderr=FALSE, ignore.stdout=FALSE) > (with various permutations of TRUE/FALSE for the options) but I cannot capture what is displayed on the console. > > I have also tried ?system2? with various TRUE/FALSE permutations without success. > > Any clever ideas? >?Sys.which HTH, CCB
Dirk I am now more confused (and I appreciate your help in sorting this out). I executed require(?rJava?) and received the following error:> Error: package or namespace load failed for ?rJava?: > .onLoad failed in loadNamespace() for 'rJava', details: > call: dyn.load(file, DLLpath = DLLpath, ...) > error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so': > dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib > Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so > Reason: image not found >Java is definitely installed on this machine ? from a terminal: PET513> Java -version java version "13.0.1" 2019-10-15 Java(TM) SE Runtime Environment (build 13.0.1+9) Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing) It appears that the problem relates to version # ? I have 13.03.1 installed whereas R is looking for 11.0.1 Any idea how to fix this? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com> On Nov 9, 2019, at 9:35 AM, Dirk Eddelbuettel <edd at debian.org> wrote: > > > Dennis, > > R does that for you already as it needs to know it for rJava too. > > On my (Linux) box: > > edd at rob:~$ R CMD config JAVA > /usr/lib/jvm/default-java/bin/java > edd at rob:~$ R CMD config JAVA_HOME > /usr/lib/jvm/default-java > edd at rob:~$ > > You could also do the equivalent of `which` or `type -p` from R: > > R> Sys.which("javac") > javac > "/usr/bin/javac" > R> Sys.which("javacdoesnotexist") > javacdoesnotexist > "" > R> > > Hope this helps, Dirk > > -- > http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
> I would like to capture this output in R using the system command, then search for ?No Java runtime installed? )or the correponding text in Windows). > > I execute something like: > CAPTURE <- system("Java -version", intern=TRUE, ignore.stderr=FALSE, ignore.stdout=FALSE) > (with various permutations of TRUE/FALSE for the options) but I cannot capture what is displayed on the console.That's fascinating... I'm offsite, I'll try it tomorrow... Two questions: (1) What is the value of CAPTURE (or does it hang)? (2) Can you run other java commands ("java MyClass", "javac MyClass.java", etc)? Another thing, did you try Duncan's suggestion? If that doesn't work, another possibility is to pipe the output, to a command line app that echos the text.