List directory using Java getRuntime on MAC

0

In Java I am trying to open the mac terminal and execute a command to list folder 'ls'.

Follow the code

public String executeCommand() {
String[] commandWithParameters = null;    
            commandWithParameters = new String[]{
                "/usr/bin/open",
                "/Applications/Utilities/Terminal.app",
                "ls"
            };
        try {
            Process terminal = 
               Runtime.getRuntime().exec(commandWithParameters);

        } catch (IOException ex) {

       }
    }
}

But it does not open the terminal, if I remove the 'ls' it opens the window. On Windows this structure works, however the cmd open statement is different.

Someone knows a correct algorithm to mount the logic to open the terminal and execute the command.

    
asked by anonymous 27.03.2018 / 23:46

0 answers