Same as exec() above, but prefixes the call with a shell.
(StringList stdout, StringList stderr, String... args)
| 3676 | * Same as exec() above, but prefixes the call with a shell. |
| 3677 | */ |
| 3678 | static public int shell(StringList stdout, StringList stderr, String... args) { |
| 3679 | String shell; |
| 3680 | String runCmd; |
| 3681 | StringList argList = new StringList(); |
| 3682 | if (platform == WINDOWS) { |
| 3683 | shell = System.getenv("COMSPEC"); |
| 3684 | runCmd = "/C"; |
| 3685 | } else { |
| 3686 | shell = "/bin/sh"; |
| 3687 | runCmd = "-c"; |
| 3688 | // attempt emulate the behavior of an interactive shell |
| 3689 | // can't use -i or -l since the version of bash shipped with macOS does not support this together with -c |
| 3690 | // also we want to make sure no motd or similar gets returned as stdout |
| 3691 | argList.append("if [ -f /etc/profile ]; then . /etc/profile >/dev/null 2>&1; fi;"); |
| 3692 | 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;"); |
| 3693 | } |
| 3694 | for (String arg : args) { |
| 3695 | argList.append(arg); |
| 3696 | } |
| 3697 | return exec(stdout, stderr, shell, runCmd, argList.join(" ")); |
| 3698 | } |
| 3699 | |
| 3700 | |
| 3701 | /* |