how can i get access to write /etc/hosts
Answered
I am developing a plugin to update file /etc/hosts on Mac, but this file is read only, how can i get access to write /etc/hosts
Please sign in to leave a comment.
You can try using
Thank you for your help, Jakub Chrzanowski, it works.
For simple command, we can use ExecUtil.sudo, but for "echo", we need to use script like this
StringBuilder shellScript = new StringBuilder("#!/bin/sh\n");
for (String writeLine : writeLines) {
shellScript.append(String.format("echo %s >> /etc/hosts\n", writeLine));
}
File script = ExecUtil.createTempExecutableScript("modify_hosts", ".sh", shellScript.toString());
GeneralCommandLine scriptCommandLine = new GeneralCommandLine(script.getPath());
ProcessOutput output = ExecUtil.sudoAndGetOutput(scriptCommandLine, "modify /etc/hosts");