/** * Launch a process using a platforms shell. This version uses an array * to make it easier to deal with spaces in the individual elements. * (This avoids the situation of trying to put single or double quotes * around different bits). */ static public Process open(String argv[]) { return exec(argv); }
Process p = exec(args); int result = -1; try {
Process p = exec("defaults", "read", "com.apple.spaces", "spans-displays"); BufferedReader outReader = createReader(p.getInputStream()); BufferedReader errReader = createReader(p.getErrorStream());
/** * Same as exec() above, but prefixes the call with a shell. */ static public int shell(StringList stdout, StringList stderr, String... args) { String shell; String runCmd; StringList argList = new StringList(); if (platform == WINDOWS) { shell = System.getenv("COMSPEC"); runCmd = "/C"; } else { shell = "/bin/sh"; runCmd = "-c"; // attempt emulate the behavior of an interactive shell // can't use -i or -l since the version of bash shipped with macOS does not support this together with -c // also we want to make sure no motd or similar gets returned as stdout argList.append("if [ -f /etc/profile ]; then . /etc/profile >/dev/null 2>&1; fi;"); argList.append("if [ -f ~/.bash_profile ]; then . ~/.bash_profile >/dev/null 2>&1; elif [ -f ~/.bash_profile ]; then . ~/.bash_profile >/dev/null 2>&1; elif [ -f ~/.profile ]; then ~/.profile >/dev/null 2>&1; fi;"); } for (String arg : args) { argList.append(arg); } return exec(stdout, stderr, shell, runCmd, argList.join(" ")); }