0

I have a bash script that runs fine from the terminal, but when I attempt to execute it from my Java program using ProcessBuilder it fails with TERM environment variable not set:

 ProcessBuilder pb = new ProcessBuilder( "./my_script", "my_param");
 pb.redirectErrorStream(true);
 pb.directory("../../");
 Process p = pb.start();
 ...

There is a similar question here which reports the same problem when running a bash script, however in my case this only happens when I run it from Java ProcessBuilder. I am curious to understand why.

Thank you for your attention.

João Matos
  • 6,102
  • 5
  • 41
  • 76
  • How is your Java program started? From the terminal or as a service or daemon? – Charles Duffy Mar 03 '20 at 14:31
  • ProcessBuilder *can* change the environment of the program it starts, but it defaults to the environment of the parent process (the JVM itself), which is normal practice for all UNIX programs. – Charles Duffy Mar 03 '20 at 14:33
  • So, look at the environment variables set for your JVM. Keep in mind, though, that TERM doesn't make *sense* for services or cron jobs since they don't run in a terminal at all, so there's no such thing as a terminal type for them. – Charles Duffy Mar 03 '20 at 14:34
  • The duplicate you link really is a duplicate. The parent JVM plays the same role here (as a parent process that doesn't have TERM set) that cron does there. If that's not true, edit to show evidence to that effect, ping me, and I'll reopen. – Charles Duffy Mar 03 '20 at 14:48

0 Answers0