Question

I'm running process builder and trying to source /etc/profile to be able to execute commands that work in a regular shell.

String args[] = {"source", "/etc/profile"};
Process p = new ProcessBuilder(args).start();
InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);

Unfortunately it returns:

java.io.IOException: Cannot run program "source": java.io.IOException: error=2, No such file or directory

Any help greatly appreciated!

Was it helpful?

Solution

bash supports the environment variable BASH_ENV on startup. Set the variable to your script and its contents will be sourced before execution. See bash(1) for details.

(was able to get the answer through another question - Setting a java ProcessBuilder environment with a bash script)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top