I'm writing a program for work and a certain part of the code uses Process
and ProcessBuilder
to run some system commands.
I'm developing it in a Linux Mint machine but the program will run in Ubuntu 20.04 GNOME.
When I build the maven project as javafx:jlink (because I'm going to build it as a .deb package) and run the bin/app
script that gets created. I get this error in the console.
java.io.IOException: Cannot run program "uptime": error=13, Permission denied
I've already searched other threads and they all say the same thing that I have to give the user running the program permissions to that executable with chmod u+x /usr/bin/uptime
. It doesn't work.
Originally this part of the code was using Process
, switched to ProcessBuilder
and still didn't do anything. I even went as far as to make the user owner of /usr/bin/uptime
and I still get that error.
This is what I'm currently working with:
// Set Uptime
try{
Process p = new ProcessBuilder().command("uptime","-p").start();
InputStream in = p.getInputStream();
uptime = new String(in.readAllBytes());
p.destroy();
}catch (IOException err){
System.out.println(err.getMessage());
err.printStackTrace();
}
The only difference that I can think of is that in my Linux Mint machine, my user is Administrator where as the test machine, the user is a regular user.
I disabled AppArmor thinking it was causing issues, checked journalctl -xe
to see if anything odd came up and even checked /var/log/syslog
but no errors either.
If I open a regular terminal as this user, I can run these commands perfectly fine. It's getting a bit hard to pinpoint where this is giving me trouble. Any thoughts?