1

Need to run netstat -n | find ":3389" | find "ESTABLISHED" command using Java Runtime.

Tried like: Runtime.getRuntime().exec(cmd); but we can't do this if we have | (pipe) in our command.

I had found for linux command we can costruct like: String[] cmd = {"/bin/sh", "-c", "grep -c 'Report Process started' /path/to/server.log"}; Runtime.getRuntime().exec(cmd); but I need for windows, please let me know how we can do?

1

2 Answers 2

1

You should run only netstat -n and do the rest in java. You could also write a script, and execute the script instead of separate commands. If you really need to do everything in a single line that has pipes the command must be prefixed with cmd /C

Sign up to request clarification or add additional context in comments.

2 Comments

Ya that works, but checking is there any other way similar to linux. Because that way its looking much cleaner and we can find easily what we are doing.
0

In Windows we can achieve this like:

String[] cmd = { "cmd.exe", "/c",
                    "netstat -n | find \":3389\" | find \"ESTABLISHED\"" };
Process process = new ProcessBuilder(cmd).start();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.