How to run Sudo code without password in mac

Hi,

I want to run “sudo rm ing /tmp/instruments_sock” in terminal. I am doing this through code using robotil jar. But I am not able to enter password. Is there any way that I run this command without asking for password in mac.!! I want to remove password ONLY for this command.

Thamks in advance.

I’d like to note: This is not an Appium problem.

Open a terminal window and type the following:

sudo visudo

Type in your password and when the file opens go directly to the end of the file. Add the following:

<username> ALL=(ALL) NOPASSWD: ALL

Where <username> is your username.

What’s more interesting is that you’re removing a file in /tmp. If I remember my Unix correctly, shouldn’t /tmp be world-writable, so anyone should be able to delete a file from this directory?

  1. Firstly you should create FILENAME.sh file with code:
    rm ing /tmp/instruments_sock

  2. Use command to run sh file: "sh -c echo SUDO_PASSWORD | sudo -S sh “PATH/FILENAME.sh”

  3. If you want run .sh file from java code you can use code below:

String cmdline = {“sh”, “-c”, “echo SUDO_PASSWORD | sudo -S sh PATH/FILENAME.sh”};

    try {
        process = Runtime.getRuntime().exec(cmdline);
        InputStream inputStream = getProcess().getInputStream();
        InputStream errorStream = getProcess().getErrorStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 1);
        BufferedReader errorBufferedReader = new BufferedReader(new InputStreamReader(errorStream));
        String line;
        while ((line = bufferedReader.readLine()) != null){
            if (line != null) {
                System.out.println(line);
            }
        bufferedReader.close();
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }