I
I
Ivan Petrov2017-10-17 10:25:38
Java
Ivan Petrov, 2017-10-17 10:25:38

How to work with the console or cmd.exe through java?

Hello.
Tell me how can I work with the windows console in java?
I will have a JavaFX windowed application. I need to run a specific application (server) with parameters via cmd.exe. The server binds to a specific port.
At the same time, the java application must monitor the running servers, constantly check whether it works - I think it's just to check if there are running applications on the port.
How can I get a list of running applications on a specified port?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2017-10-17
@res2001

The specified port is either open (then it is captured by some one application) or closed. Using WinAPI, you can get the process ID of the process that captured the port, I don’t know if this can be done in Java, but in any case it will already be a platform-dependent solution.
There is a cmd command that shows ports and process IDs: netstat -o
You can parse its output.
It's probably easier to use some other mechanisms to monitor the server's work, for example, you can request a list of processes and analyze their command lines, or the server creates some kind of global named object, and you check for its existence: for example, a named mutex, a channel, a file, and etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question