Java - Extracting ISO to location using 7zip in Linux

Keywords: java linux javafx


So I am making an application which extracts iso to location (mainly usb mount point i.e /media/kp/mount_point)

pzip-full package is installed on my machine. So the relevant code for extracting iso from shell sudo 7z x -y 'filename' -o'location'. Sudo since I am extracting it to /media/kp/mount_point which requires root.

So in java I created a function as follows which runs the above 7z command as sudo with my sudo password and also logs and returns the output as String.

private String ExecuteShell(String command) {
    String[] cmd = {"/bin/bash","-c","echo 'mysudopass' | sudo -S "+command};
    StringBuilder joined= new StringBuilder();
    Process pb = null;
    try {
        pb = Runtime.getRuntime().exec(cmd);

        String line;
        BufferedReader input = new BufferedReader(new InputStreamReader(pb.getInputStream()));
        while ((line = input.readLine()) != null) {
    } catch (Exception e) {
    return joined.toString();

Now running it as ExecuteShell("7z x -y '"+filename+"' -o'"+location+"'");

Here is the issue, the command works fine when run from terminal but when I go with above function in Java it prints the output from 7zip as required but I don't see it written on my USB stick and it runs for only max 5 secs whereas my ISO is a big file should take atleast a min or 2.

I tried to change location as regular path like /home/kp/Desktop/folder. Here it extracts quickly with empty folders (only structure) with a lock & cross symbol on folder. See image

enter image description here

I don't know why it occurs I tried chmod +x and 777 on usb mount point and on iso file. Still it not works. Any reason why and how to resolve it?

Note: I am not just extracting iso file its just a file I am using for test. It will be used for many file types. That's why I don't want recommendation to use Loopy or java-iso-tools.