Search This Blog

Saturday, November 6, 2010

Using Java for interacting with command line

Programmer Question

I'm trying to create a Java program that is a front-end for iptables. To accomplish this, I'm using Java's Process class and pass commands.



I'm wondering if I'm going about it correctly in general. For example, here is a selection of commands that resets iptables to its default settings, which are meant to be executed in a terminal sequentially. Am I using the Process class correctly here?



Process proc1 = Runtime.getRuntime().exec("iptables -P INPUT ACCEPT");
proc1.waitFor();
Process proc2 = Runtime.getRuntime().exec("iptables -P FORWARD ACCEPT");
proc2.waitFor();
Process proc3 = Runtime.getRuntime().exec("iptables -P OUTPUT ACCEPT");
proc3.waitFor();
Process proc4 = Runtime.getRuntime().exec("iptables -t nat -P PREROUTING ACCEPT");
proc4.waitFor();


Thanks for any direction!



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails