IDEA sandbox: problems with shell command


In my plugin I need to run a python script program, which contains mostly "git", "mvn" and "java -jar". I use something like this to run my program:

Process process2=Runtime.getRuntime().exec();

The problem is that, when I run my plugin in the IDEA sandbox, the program was telling me that it cannot recognize the mvn command in my program. When I use exactly the same code to run the python script program in a normal Java Application configuration provided by IDEA, everything is fine (Mac OS system). So my guess is that the sandbox environment does not login the bash shell (specially the .bash_profile since the mvn path is stored over there).


What I have tried:

/bin/bash -l -c \"mvn --version\"

I tried to run my command like this. This command will manually login the shell first. But when I tried this in the sandbox, the command ran like forever. Also when I run command like this, it does not have any output except for the exit code. So I do not know what is happening in the sandbox when I do it in this way.

Thx in advance!



I think I solved the issue, sorry for always being such a baby :(

So the problem is that when we launch a Process in the sandbox environment, the Process will not read over the .bash_profile for some reasons. Indeed, we need to manually set up the environment variables. 

ProcessBuilder processBuilder = new ProcessBuilder(command).directory(new File(directory));
Map<String, String> map = processBuilder.environment();

String PATH = map.get("PATH") +
File.pathSeparator +"/Users/ryouyasachi/apache-maven-3.5.0/bin" +
File.pathSeparator +"/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home";

for(Map.Entry<String,String> entry: map.entrySet()){
System.out.println("env:" + entry.getKey()+" " + entry.getValue());

This is how I get the mvn command working in the my python script.


On macOS, apps launched from GUI (Dock, Finder, etc.) do not inherit a shell environment. IDEA uses a workaround to load it; you can make the loaded environment visible to a child processes by launching them with GeneralCommandLine.