Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 28 29 package org.jruby.environment; 30 31 import java.io.BufferedReader ; 32 import java.io.IOException ; 33 import java.io.InputStreamReader ; 34 import java.util.Map ; 35 36 import org.jruby.Ruby; 37 38 class OSEnvironmentReaderFromRuntimeExec implements IOSEnvironmentReader { 39 40 private final OSEnvironment environmentReader = new OSEnvironment(); 41 42 45 public boolean isAccessible(Ruby runtime) { 46 return true; 47 } 48 49 50 private String getEnvCommand() { 51 String command; 52 String osname = System.getProperty("os.name").toLowerCase(); 53 54 56 if (osname.indexOf("windows 9") > -1) { 57 command = "command.com /c set"; 58 } else if ((osname.indexOf("nt") > -1) 59 || (osname.indexOf("windows 20") > -1) 60 || (osname.indexOf("windows xp") > -1)) { 61 command = "cmd.exe /c set"; 62 } else { 63 command = "env"; 65 } 66 return command; 67 } 68 69 70 75 public Map getVariables(Ruby runtime) { 76 try { 77 Process process = Runtime.getRuntime().exec(getEnvCommand()); 78 return environmentReader.getVariablesFrom( 79 new BufferedReader (new InputStreamReader (process.getInputStream())) 80 ); 81 } catch (IOException e) { 82 environmentReader.handleException(e); 83 } 84 85 return null; 86 } 87 88 } 89
| Popular Tags
|