I'm trying to execute a command (netcat) using java and then print out the output, but nothing seems to be getting printed.
Here's my code:
import java.io.IOException;
import java.io.InputStream;
public class Test
{
public static void main(String[] args)
{
try
{
// Execute a command with an argument
//String[] commands = new String[]{"nc", "www.mywebsite.com", "1234"};
String command = "nc www.mywebsite.com 1234";
Process child = Runtime.getRuntime().exec(command);
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1)
{
System.out.print((char)c);
}
in.close();
}
catch (IOException e)
{
}
}
}