cHam
cHam

Reputation: 2664

sed not working from java program, but the input line works from terminal

When I enter the line:

sed -i 's/DNS1="8.8.8.8"/DNS1="8.8.4.4"/' /etc/sysconfig/network-scripts/ifcfg-eth0

I get the desired result (i.e. 8.8.8.8 is replaced with 8.8.4.4), however, I have a jave program that passes the same command as shown here:

public static void swapDns() throws IOException, InterruptedException 
{
    Runtime rt = Runtime.getRuntime();
    Process ps;

    String cmd[] = {"sed","-i","'s/DNS1=\"8.8.8.8\"/DNS1=\"8.8.4.4\"/'","/etc/sysconfig/network-scripts/ifcfg-eth0"};
    ps = rt.exec(cmd);
} 

and it doesn't work. It doesn't change anything. Is there an issue with sed/java, or am I missing something...

Upvotes: 0

Views: 157

Answers (1)

GL2014
GL2014

Reputation: 6694

Does the Java program perhaps run with a different environment, perhaps one where sed is not in the path? Otherwise perhaps it runs as a user who does not have write permission to the network scripts?

Upvotes: 2

Related Questions